connect to database with new PDO mysql
Posted: Wed Mar 21, 2012 6:16 am
Hi, I just new on php and have a doubt about connecting to a mysql database.
I'm trying to get work some code, and I'm unable to get this connection work.
$dsn is
mysql:dbname=myDB;host=localhost
and $user and $pass are used for connection.
this linux command works fine:
mysql --user=myUser --pass=myPass myDB
But with this code, there are not echo after PDO connection, neither 'Connected', neither 'error'
What is wrong?
Thanks
I'm trying to get work some code, and I'm unable to get this connection work.
Code: Select all
try
{
echo $dsn;
$this->dbh = new PDO($dsn, $user, $pass);
echo 'Connected';
} catch (PDOException $e)
{
echo $e->getMessage();
$err[] = 'Databse connection failed: ' . $e->getMessage();
}
mysql:dbname=myDB;host=localhost
and $user and $pass are used for connection.
this linux command works fine:
mysql --user=myUser --pass=myPass myDB
But with this code, there are not echo after PDO connection, neither 'Connected', neither 'error'
What is wrong?
Thanks