connect to database with new PDO mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dacer
Forum Newbie
Posts: 5
Joined: Wed Mar 21, 2012 6:08 am

connect to database with new PDO mysql

Post 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
dacer
Forum Newbie
Posts: 5
Joined: Wed Mar 21, 2012 6:08 am

Re: connect to database with new PDO mysql

Post by dacer »

sorry, mysql+apache was crashed and that was the problem, restarted apache and works
Post Reply