Monday, November 17, 2014

Unknown MySQL server host 'localhost:/tmp/mysql5.sock'

Unknown MySQL server host 'localhost:/tmp/mysql5.sock' error mainly occurs if the provided host name in mysqli_connect or mysqli constructor is wrong. I got this error when I connect to mysql database hosted in 1and1 server.

The sample mysqli connect code provided by 1and1 was wrong. They mixed the socked name with host name. According to mysqli documentation the first parameter should be domain name or IP. So use only host name (commonly localhost or IP) as the first parameter and include socket as the sixth parameter if required.

Here is the working code in both oop and procedural way.

No comments:

Post a Comment