Page 1 of 1

connect to database with new PDO mysql

Posted: Wed Mar 21, 2012 6:16 am
by dacer
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.

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();
    }
$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

Re: connect to database with new PDO mysql

Posted: Wed Mar 21, 2012 7:14 am
by dacer
sorry, mysql+apache was crashed and that was the problem, restarted apache and works