php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-31 12:02 UTC] sjon@php.net
-Status: Open +Status: Verified
 [2019-07-31 12:02 UTC] sjon@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC