0

I have a website hosted by DreamHost. The subdomain "fakestore" has a database, and consequently a script to access that database. However, I am unable to get that database to work. I've tried changing $servername to 127.0.0.1, and to aashishbharadwaj.com. If I use localhost, I get the error It no work!SQLSTATE[HY000] [2002] No such file or directory. If I use the other two I get 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();
    }
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aashishkebab
  • 295
  • 3
  • 10

1 Answers1

0

I suggest you check the hostname created when creating the database, according to https://help.dreamhost.com/hc/en-us/articles/215733647-What-PHP-commands-do-I-use-to-connect-to-my-database-

If you want to use localhost - please read https://stackoverflow.com/a/1819767/5920627

kay27
  • 897
  • 7
  • 16