3

Simply connecting to mysql server, username password and host all are correct.

Still mysql_error() throws the following error:

Warning: mysql_connect(): No such file or directory in 
save.php on line 6
No such file or directory

When I change it from 'localhost' to '127.0.0.1', it gives error:

Warning: mysql_connect(): Connection refused in 
save.php on line 6
Connection refused

The same connection is working without any issue for a wordpress website on the same host.

When I enter wrong password, mysql throws error of password not exist

What does it mean ?

[Update]

I checked my phpinfo() and

mysql.default_socket    no value    no value

same for default_host, user, password etc.

I tried

ini_set("mysql.default_socket","/var/run/mysqld/mysqld.sock");

as mention in php.ini but no luck.

Again its working for a wordpress previous install and its wp_config has the same mysql access. For wrong password sometime it throws "password not exist"

justnajm
  • 4,422
  • 6
  • 36
  • 56
  • What is there on line 6? – Hüseyin BABAL Apr 21 '14 at 05:53
  • possible duplicate of [Warning: mysql\_connect(): \[2002\] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in](http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi) – Rikesh Apr 21 '14 at 05:54
  • @HüseyinBABAL is mysql_connect('','','') – justnajm Apr 21 '14 at 05:58
  • Have you searched SO for this? There are lots of question about your case as @Rikesh stated – Hüseyin BABAL Apr 21 '14 at 05:59
  • Yes I do, thats why I changed my localhost to 127.0.0.1, and it threw a new error. Just now I have tried ini_set('mysql.default_socket','/var/run/mysqld/mysqld.sock') – justnajm Apr 21 '14 at 06:01

1 Answers1

0

Even i had faced similar problem. Please try this, hope it may works for you. Use mysqli instead of mysql

// Create connection

$domain   = "localhost";  // or yourdomainname.com
$username = "root";       // db username
$password = "pass123";    // db password
$dbName   = "gymchalo";   // db name

$con = mysqli_connect($domain,$username,$password,$dbName);

// Check connection
if (mysqli_connect_errno()){

    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    die('Mysql connection error');
}else{
    echo "Connection Established";
}
Vinit Kadkol
  • 1,221
  • 13
  • 12
  • Warning: mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in save.php on line 5 Failed to connect to MySQL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)Mysql connection error – justnajm Apr 21 '14 at 06:10