Bug #78347 [Opn->Ver]: wrong socket path when host field is empty
| From: | sjon@php.net | Date: | Wed, 31 Jul 2019 12:02:18 +0000 |
| Subject: | Bug #78347 [Opn->Ver]: wrong socket path when host field is empty | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222025@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78347&edit=1
ID: 78347
Updated by: sjon@php.net
Reported by: l dot fuerderer at gmail dot com
Summary: wrong socket path when host field is empty
-Status: Open
+Status: Verified
Type: Bug
Package: PDO MySQL
Operating System: Arch Linux
PHP Version: 7.3.7
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2019-07-29 12:03:55] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78347&edit=1