phpList / phplist-plugin-restapi

REST API as a plugin for phpList/phpList3
http://resources.phplist.com/plugin/restapi
GNU Affero General Public License v3.0
21 stars 31 forks source link

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

Open reetp opened 10 months ago

reetp commented 10 months ago

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';
michield commented 10 months ago

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

reetp commented 10 months ago

Yup I can give it a go!

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