lundi 29 décembre 2014

Cannot connect to mysql server


Hello I am trying to connect to mysql server from php using PDO.


But I get this error :


An error occured : SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


Note that this is not a database I host. I was simply given the username and password to construct the database, create the users etc.



function ConnectToDb()
{
try{
$dns = 'mysql:host=1.1.1.1;dbname=dummyDbName';
$username = 'dummyUser';
$password = 'dummyPassword';
$LINK = new PDO($dns, $username, $password);
$LINK->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$LINK->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (!$LINK){
die('Could not connect : ' .mysql_error());
}
else{
return $LINK;
}
} catch (PDOException $ex){
echo "An error occured : " .$ex->getMessage();
}
}


I know that this works on localhost. I'm using it no problem, but as soon as I try to connect to the production database it fails. Anyone has an hint?





Aucun commentaire:

Enregistrer un commentaire