I've successfully established a few PDO/PHP connections to mySQL. All these connections were to databases stored on different hosting servers. Now - just as an exercise in learning - I am trying to establish a PDO/PHP connection to mySQL on my own system. I've successfully established a connection to my office hard drive, from mySQL Workbench installed on my laptop.. so I know it's doable.
But when I try to set a PDO/PHP connection I can't make a go of it. Following is my script:
Code: Select all
//Define Database
$hostname = '000.000.0.00'; // IP address
$dbname= 'test'; // name of schema I'm trying to connect to.
$username = 'root';
$password = 'password'; // password is correct
// Create PDO link to the database with the following "try" block
try
{
$link = new PDO("mysql:host=$hostname;port=3306;dbname=$dbname", $username, $password);
echo "a link has been established to homebase.";
}
// This block throws an error message if there is no connection. PDO uses "exceoptions" to handle errors.
catch(PDOException $e) {
echo "There is an error somewhere. I have no idea where, but there is an error.<br />";
echo "The error: " . $e . "<br />";
// The following echo will return php generated message. Use for stepping through an error.
// echo $e->getMessage();Any assistance in this area is appreciated.The error: exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '000.000.0.000' (110)' in /home/user/public_html/include/connect.php:15 Stack trace: #0 /home/user/public_html/include/connect.php(15): PDO->__construct('mysql:host=000....', 'root', 'password') #1 {main}
Thanks in advance:
Pavilion