我有以下代码:
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;
}
它没有错误地连接到第一台服务器(不是本地服务器),但是随后却无法连接到本地服务器。我收到此错误消息:
错误:SQLSTATE [HY000] [2002]没有这样的文件或目录(||)
我正在运行PHP v5.4.27
解决了。从localhost更改为127.0.0.1似乎可以解决此问题。我不确定为什么
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句