haenik kamdar haenik kamdar - 5 months ago 63
SQL Question

Mysql Operation timeout Error

Warning: mysqli_connect(): (HY000/2002): Operation timed out in /Applications/XAMPP/xamppfiles/htdocs/conn.php on line 4
Connection failed: Operation timed out


Get the following error while connecting to XAMPP on Mac OS X.
Code line is

$conn=mysqli_connect("SNA","root","","localhost");

// Check connection
if (mysqli_connect_errno()) {
echo "Connection failed: " . mysqli_connect_error();
}


Is it a Mysql Host problem or a Mysql default socket problem and how to resolve it? Default Host is 3306. I dont know where my mysql.sock file is generated and whether its generating or not.

Answer

change your code here, interchange host and database name

 $conn=mysqli_connect("localhost","root","","SNA");

check php manual for more info : http://php.net/manual/en/function.mysqli-connect.php