phpList/phplist-plugin-restapi

No DB server port or socket from configuration.php set in pdo.php

Opened this issue · 2 comments

I discovered that this file:

admin/plugins/restapi/includes/pdo.php

does not check the server port specified in the config file.

My quick fix was:

--- pdo.php.old	2024-01-05 18:38:56.724455609 +0100
+++ pdo.php	2024-01-05 18:07:00.221162380 +0100
@@ -15,7 +15,8 @@
         $dbuser = $GLOBALS['database_user'];
         $dbpass = $GLOBALS['database_password'];
         $dbname = $GLOBALS['database_name'];
-        $dbh = new \PDO("mysql:host=$dbhost;dbname=$dbname;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
+        $dbport = $GLOBALS['database_port'];
+        $dbh = new \PDO("mysql:host=$dbhost;dbname=$dbname;port=$dbport;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 
         return $dbh;

It also doesn't appear to use a socket either even if specified in the config file eg this format:

$dsn = 'mysql:dbname=testdb;unix_socket=/path/to/socket';

Thanks, would you be able to turn that into a Pull Request, so we can process it?

Yup I can give it a go!

I'll try and add the socket option if that is detected in the config.