php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71829 PHP not able to connect to mySQL database
Submitted: 2016-03-15 16:28 UTC Modified: 2016-03-18 17:22 UTC
From: jfha73 at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 7.0.4 OS: Linux
Private report: No CVE-ID: None
 [2016-03-15 16:28 UTC] jfha73 at gmail dot com
Description:
------------
All it gets is this:

SQLSTATE[HY000] [2002] No such file or directory

MySQL can be accessed via console, just not using PHP with phpMyAdmin or a WebApp that uses MySQL.

Any idea what I can do about this?

Thanks.

Test script:
---------------
phpMyAdmin

Expected result:
----------------
Connect to mySQL database server

Actual result:
--------------
Error saying No such file or directory.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-15 16:42 UTC] jfha73 at gmail dot com
Update to the ticket, it does work when I connect using IP address (127.0.0.1) but when name (localhost) is used, I checked my /etc/hosts and it has 127.0.0.1 set as localhost, also my firewall is disabled.
 [2016-03-15 17:15 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-03-15 17:15 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Specifying "localhost" as the hostname will try to use a socket file. Your MySQL server may not have created one.
 [2016-03-16 15:09 UTC] jfha73 at gmail dot com
I just re-configured my mysql to create the mysql.sock at /tmp/mysql.sock and edited php.ini to read mysql.default_socket where the mysql.sock is and it still won't connect using name (localhost), I can see the newly created mysql.sock file in /tmp, but PHP 7.0.4 seems not to be able to locate it, any other ideas?

Thanks.
 [2016-03-17 15:11 UTC] jfha73 at gmail dot com
This is weird, if I run:

php mysqltest.php

it works, but if I do it via web it says it cannot find the file, any ideas?
 [2016-03-17 15:14 UTC] requinix@php.net
This isn't really the best place for general help. Try a mailing list or online forum.
http://php.net/support.php
 [2016-03-18 17:22 UTC] jfha73 at gmail dot com
More info:

I just created a script to test socket access to /tmp/mysql.sock and it tested successfully, so if PHP can open a socket file in the place where it's supposed to be, why can't it open it using mysqli_connect("localhost", "user", "password", "database");

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 23:01:27 2024 UTC