I'm trying to make a simple HTML form that will add data to a remotely hosted My SQL database. I'm pulling my hair out because the connection code that I made yesterday stopped working today for no apparent reason.
Here's the code I had:
<?php
$servername = "sql309.myservername.com";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
try {
$conn = new PDO("mysql:host=$servername;dbname=mydbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
The error message that I get is: "Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'myusername'@'an.ip.address' (using password: YES)"
I noticed that phpmyadmin has my username listed as 'myusername@a.different.ip.address', and when I replaces the username string with 'myusername@a.different.ip.address', the error message becomes:
"Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'myusername@a.different.ip.address'@'an.ip.address' (using password: YES)"
How do I tell the code to use 'myusername'@'a.different.ip.address' ? Or is there a different problem?