title: SQLSTATE[3D000]:1046 - No database selected
body: <p>I was trying to execute a SQL CREATE command with php but I have this problem:</p>
  
  <blockquote>
    <p>SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected</p>
  </blockquote>
  
  <p>I REALLY can't know where is the problem, please could you help me?</p>
  
  <p>This is the script:</p>
  
  <pre><code>&lt;?php
  
  include 'connessione.php';
  
  try {
      $sql = 'CREATE TABLE joke (
              id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
              joketext TEXT,
              jokedate DATE NOT NULL 
              ) DEFAULT CHARACTER SET uft8 ENGINE=InnoDB';
      $pdo-&gt;exec($sql);
  } catch (PDOException $e){
      $output = 'Errore nella creazione della tabella joke: ' . $e-&gt;getMessage();
      include 'output.html.php';
      exit();
  }
  
  $output = 'Tabella creata con successo.';
  include 'output.html.php';
  
  ?&gt;
  </code></pre>
  
  <p>And here the "connessione.php" file:</p>
  
  <pre><code>&lt;?php
  
  $host = 'host=localhost'; 
  $mysql_user = 'root';
  $mysql_password = '';
  $database = 'php';
  
  try { 
      $pdo = new PDO('mysql:$host;dbname=$database', $mysql_user, $mysql_password); 
      $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
  } catch (PDOException $e) {
      $output = 'Impossibile connettersi al database: ' . $e-&gt;getmessage();
      include 'output.html.php';
      exit();
  }
  
  ?&gt;
  </code></pre>
  
  <p>I checked the "connessione.php" file and the connection to database is right. Also, I checked user privileges and root has all privileges to "php" database... What's the problem?! </p>