“连接被拒绝”或“没有这样的文件或目录”

34gzjxbg  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(356)

我有一个由dreamhost主持的网站。子域“fakestore”有一个数据库,因此有一个访问该数据库的脚本。但是,我无法让数据库工作。我试过换衣服 $servername127.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();
    }
?>
ijxebb2r

ijxebb2r1#

我建议您检查在创建数据库时创建的主机名,根据https://help.dreamhost.com/hc/en-us/articles/215733647-what-php-commands-do-i-use-to-connect-to-my-database-
如果你想用 localhost -请阅读https://stackoverflow.com/a/1819767/5920627

相关问题