Avatar of csehz
csehz
Flag for Hungary asked on

MySQL/Php - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (96)

Dear Experts,

I have found this small Php code on a great site (http://www.plus2net.com/php_tutorial/php_paging-download.php), basically targeting of the pagination of an MySQL table:

<?Php
$dbhost_name = "localhost";
$database = "xx";// database name
$username = "xx"; // user name
$password = "xx"; // password 

//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?> 

Open in new window


I am sure that it works, however not at my internet service provider (Yahoo Small Business account), because at running this code bringing an error message:

Error!: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (96)

I would like to understand what does that mean and eventually what to change for having it working. With other methods with other php codes I am able to login to the database and running queries, but with this one not

Thanks,
MySQL ServerPHPDatabases

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

That means that you probably have not used the correct credentials.  Many hosting companies did not put the MySQL server on the same machine as the web site.  That would use 'localhost'.  There is probably a different server name or IP address for the MySQL server for your account.  You need to look it up and use that.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

I noticed (after posting) that he said that he could connect "with other php codes".  He probably just needs to copy the credentials from those files to this one.
csehz

ASKER
Thanks very much the answers, sorry for the late during the holidays period was not able to test it.

Yes as you also mentioned with other codes I can login without any issue, for example with this:

<?Php
$connect = mysql_connect("mysql", "xx", "xx") or
			die ("Check your server connection.");
		$k = "SET NAMES latin2"; mysql_query($k);
		mysql_select_db("lang") or die(mysql_error());
?> 

Open in new window


Comparing this code to that original one in the question, which is maybe not clear the $db_host = "localhost"; but in my understanding that should be left as unchanged?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
csehz

ASKER
Thanks for your assist in the question
Dave Baldwin

You're welcome.