문제

I have the following code:

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;
    }

It connects without errors to the first server (not local), but then it fails to connect to the local server. I get this error message:

Error: SQLSTATE[HY000] [2002] No such file or directory (||)

I'm running PHP v5.4.27

도움이 되었습니까?

해결책

Solved it. Changing from localhost to 127.0.0.1 seems to fix it. I'm not sure why

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top