|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
44 - 37 = ?
Subscribe to this entry?

 [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 22:01:29 2024 UTC