1
我有以下代码:错误连接到本地数据库服务器
try {
$db_conn = new PDO('mysql:host='.$host.';dbname=stats;port='.$port, $un, $pw);
} catch (PDOException $e) {
WriteLog("Could not connect to database!\nError: ".$e->getMessage());
exit;
}
try {
$db_conn2 = new PDO('mysql:host=localhost;dbname=log', $un2, $pw2);
} catch (PDOException $e) {
WriteLog("Could not connect to database[2]!\nError: ".$e->getMessage());
exit;
}
它连接没有错误的第一台服务器(非本地),但随后无法连接到本地服务器。我得到这个错误信息:
Error: SQLSTATE[HY000] [2002] No such file or directory (||)
我运行PHP v5.4.27
@ShankarDamodaran:它没有解决它。我的.sock文件的位置在my.cnf和php.ini中是一样的 – Cornwell