| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2019-07-29 12:03 UTC] l dot fuerderer at gmail dot com
 Description:
------------
In my Arch Linux I activated PDO MySql in the php.ini to connect to Mariadb:
extension=pdo_mysql
And I changed the socket path:
pdo_mysql.default_socket=/run/mysqld/mysqld.sock
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:
---------------
<?php
// 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 08:00:01 2025 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: https://github.com/php/php-src/blob/eea206a06c6fcbcbabc590d287dc529588520095/ext/mysqlnd/mysqlnd_connection.c#L551