Not able to connect to MYsql with php

Hi,

I am using XAMPP & I am not able to connect MySQL with PHP. I am a novice & learning from a book "php_mysql novice to ninja 5th edition"

when I type the following query in PhpMyAdmin

<?php
try
{
$pdo = new PDO(‘mysql:host=localhost;dbname=ijdb’, ‘ijdbuser’,
‘mypassword’);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec(‘SET NAMES “utf8”’);
}
catch (PDOException $e)
{
$output = ‘Unable to connect to the database server.’;
exit();
}

I get the following error.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php
try
{
$pdo = new PDO(‘mysql:host=localhost:8888;dbname=ijdb’, ‘ijdbuser’,
‘’ at line 1

Please help me to solve this problem

Hi,

It looks like you’re putting PHP code into phpMyAdmin when it’s expecting SQL. If you want to test the code you’ve shown above, you need to put it in a file with a .php extension and then run it from your server.