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();
}
?>