2014-04-07 81 views
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

+0

@ShankarDamodaran:它没有解决它。我的.sock文件的位置在my.cnf和php.ini中是一样的 – Cornwell

回答

1

解决它。从localhost更改为127.0.0.1似乎解决了这个问题。我不知道为什么

+0

Good job mate ..很高兴你解决了它。投票你。 –

相关问题