Problem with my connection script: It wont connect to DB. Why?
Error message in the bottom.
<?php
define("host",'mysqlserver.no'); // Default database host.
define("dbname", 'mydbname'); // Default database name.
define("username",'myusername'); // Deafault database username .
define("password",'mypassword'); // Default database password.
function pdoConnect($dbname=database)
{
$db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
return $db;
}
try {
$pdo = new PDO('mysql:host=mysqlserver.no;mydbname=mydb', 'myusername',
'mypassword');
$output = 'Database connection established.';
}
catch (PDOException $e) {
$output = 'Unable to connect to the database server: ' . $e->getMessage();
}
?>
This is the ERROR message printed out on screen. Why?:
Unable to connect to the database server: SQLSTATE[HY000] [2002] Connection refused