title: Mysql - PDO Error - Invalid catalog name: 1046 No database selected
body: <p>I have a problem with PDO, and I see absolutely no where he come. I can not question my MySQL database. Just to test I used the following code (having quite sour previously configured the parameters for the connection:</p>
  
  <pre><code>try {
      $dbh= new PDO('mysql:host=serverName;dbname=Mydatabase','user','password');
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
  catch (Exception $e) {
      die('Erreur : ' . $e-&gt;getMessage());
  }
  
  var_dump($dbh);    // gives : object(PDO)#1 (0) { }
  
  $res=$dbh-&gt;query('SELECT * FROM table');
  </code></pre>
  
  <p>The connection is made correctly with MySQL but after query I get this error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected' in /home/outout/public_html/file.php:16 Stack trace: #0 /home/outout/public_html/file.php(16): PDO->query('select * from t...') #1 {main} thrown in /home/outout/public_html/file.php on line 16.</p>
  </blockquote>
  
  <p>The code works on a local machine, but as soon as I put it online (cPanel) it shows me this error. Do I have to configure PDO in .htaccess?</p>
  
  <p>I absolutely do not understand where the problem come. Someone would have an idea?</p>