"Connection Refused" 或 "No Such File or Directory"

"Connection Refused" or "No Such File or Directory"

我有一个由 DreamHost 托管的 website。子域 "fakestore" 有一个数据库,因此有一个访问该数据库的脚本。但是,我无法使该数据库正常工作。我试过将 $servername 更改为 127.0.0.1,然后更改为 aashishbharadwaj.com。如果我使用本地主机,我会收到错误 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();
    }
?>

我建议你检查创建数据库时创建的主机名,根据https://help.dreamhost.com/hc/en-us/articles/215733647-What-PHP-commands-do-I-use-to-connect-to-my-database-

如果您想使用 localhost - 请阅读