Hello,
Looking for a bit of help if possible. I’m using PDO for the first time to connect to a database and then query it. Now the PDO connection I have created is like so:
try {
$dbh = 'mysql:host=ddddddddddd;dbname=sssssssssssss';
$dbc = new PDO($dbh, 'iiiiiiiiiiiiiii','xxxxxxxxxxxxxx');
$dbc ->setAttribute(PDO::ATTR_EMULATE_PREPARES, True);
$dbc ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "sucessfully connected";
} catch (PDOException $e) {
echo 'Failed: ' .$e->getMessage();
}
?>
Now I know this connection is working as I echo “sucessfully connected” in the try/catch block to my page.
However on a page where I include my connection and query a database like so:
//Include PDO connection
include('connect.php');
$result = mysql_query("SELECT * from db");
$num = mysql_num_rows($result);
$n = 0;
while($row = mysql_fetch_array($result)){
echo ''.$row['name'].''';
}
It then shows a load of ‘access denied’ messages, A link to the server could not be established etc when I run that query?
Any ideas?