代码之家  ›  专栏  ›  技术社区  ›  Aashishkebab

“连接被拒绝”或“没有此类文件或目录”

  •  0
  • Aashishkebab  · 技术社区  · 8 年前

    我有一个 website 由DreamHost托管。子域“fakestore”有一个数据库,因此有一个访问该数据库的脚本。然而,我无法使该数据库正常工作。我试过换衣服 $servername 127.0.0.1 ,和至 aashishbharadwaj.com 。如果使用localhost,则会出现错误 It no work!SQLSTATE[HY000] [2002] No such file or directory .如果我用另外两个 It no work!SQLSTATE[HY000] [2002] Connection refused

    <?php
        $servername = 'localhost';   //I've tried numerous things here, with different errors
    
        //For my server
        $username = "username";   //Not actual username
        $password = "password";   //Not actual password
    
        $dbname = 'database_name';   //Not actual database name
    
        try {
            $db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        } catch (PDOException $e) {
            $error_message = $e->getMessage();
            echo "It no work!";
            echo $error_message;
            exit();
        }
    ?>
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   kay27    8 年前
    推荐文章