|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78347 wrong socket path when host field is empty
Submitted: 2019-07-29 12:03 UTC Modified: 2019-07-31 12:02 UTC
From: l dot fuerderer at gmail dot com Assigned:
Status: Verified Package: PDO MySQL
PHP Version: 7.3.7 OS: Arch Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: l dot fuerderer at gmail dot com
New email:
PHP Version: OS:


 [2019-07-29 12:03 UTC] l dot fuerderer at gmail dot com
In my Arch Linux I activated PDO MySql in the php.ini to connect to Mariadb:

And I changed the socket path:

When I connect to the database giving an empty hostname, PHP tries to connect to /tmp/mysql.sock ignoring the php.ini setting. (I saw this using strace)

Test script:
// the following two lines work
new \PDO("mysql:", "http", "");
new \PDO("mysql:host=localhost", "http", "");

// this line fails
new \PDO("mysql:host=", "http", "");

Expected result:
Three successful connections, no output.

Actual result:
PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /srv/http/databases.php:7
Stack trace:
#0 /srv/http/databases.php(7): PDO->__construct('mysql:host=', 'http', '')
#1 {main}
  thrown in /srv/http/databases.php on line 7


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-31 12:02 UTC]
-Status: Open +Status: Verified
 [2019-07-31 12:02 UTC]
I can confirm this; to reproduce:

$ strace -econnect php -n -dextension=pdo_mysql -dpdo_mysql.default_socket=/run/mysqld/mysqld.sock -r 'new \PDO("mysql:host=", "http", "");' >/dev/null 
connect(3, {sa_family=AF_UNIX, sun_path="/tmp/mysql.sock"}, 17) = -1 ENOENT (No such file or directory)
+++ exited with 255 +++

while leaving off "host=" or changing it to "host=localhost" actually works

It seems like this might be the cause:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 20:01:30 2024 UTC