]> git.mxchange.org Git - friendica.git/commitdiff
mysql connection via unix sockets (mysqli + PDO)
authork-alin <63866963+k-alin@users.noreply.github.com>
Mon, 14 Feb 2022 22:18:41 +0000 (23:18 +0100)
committerk-alin <63866963+k-alin@users.noreply.github.com>
Mon, 14 Feb 2022 22:18:41 +0000 (23:18 +0100)
src/Database/Database.php

index f478d7993a1844dfac0f49c76da20f1c6bcef8a3..effed6e5e9be972ff4e38c75b6e4492d3282af87 100644 (file)
@@ -114,6 +114,7 @@ class Database
                $pass    = trim($this->configCache->get('database', 'password'));
                $db      = trim($this->configCache->get('database', 'database'));
                $charset = trim($this->configCache->get('database', 'charset'));
+                $socket  = trim($this->configCache->get('database', 'socket')); 
 
                if (!(strlen($server) && strlen($user))) {
                        return false;
@@ -125,7 +126,7 @@ class Database
 
                if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
                        $this->driver = self::PDO;
-                       $connect      = "mysql:host=" . $server . ";dbname=" . $db;
+                       $connect      = "mysql:host=" . $server . ";dbname=" . $db . ";unix_socket=" . $socket;
 
                        if ($port > 0) {
                                $connect .= ";port=" . $port;
@@ -149,9 +150,9 @@ class Database
                        $this->driver = self::MYSQLI;
 
                        if ($port > 0) {
-                               $this->connection = @new mysqli($server, $user, $pass, $db, $port);
+                               $this->connection = @new mysqli($server, $user, $pass, $db, $port, $socket);
                        } else {
-                               $this->connection = @new mysqli($server, $user, $pass, $db);
+                               $this->connection = @new mysqli($server, $user, $pass, $db, $socket);
                        }
 
                        if (!mysqli_connect_errno()) {