Vote Up 0 Vote Down

could not connect to server: Connection refused Is the server running on host "localhost"

I got the error :

could not connect to server: Connection refused Is the server running on host "localhost"

I'm using mysql and the following is my connection code for PDO :

try {
$db = new PDO("pgsql:dbname={$db_name};host={$db_host}", "{$db_username}", "{$db_password}");
} catch (PDOException $e) {
echo $e->getMessage();
}
flag

Answers


Vote Up 0 Vote Down
You said you are using mysql, but you are connecting to Postgresql instead of Mysql.

Change your code like below :

try {
$db = new PDO("mysql:dbname={$db_name};host={$db_host}", "{$db_username}", "{$db_password}");
} catch (PDOException $e) {
echo $e->getMessage();
}
flag | link |

Your Answer

Login before answering

Login with facebook