title: PHP/MYSQL - Drop database using prepared statement
body: <p>I would like to drop a database using PDO. </p>
  
  <p>This approach was the best one to me</p>
  
  <pre><code>function delete_db($database)
  {
    $statement = $my_pdo_obj-&gt;prepare("DROP DATABASE IF EXISTS :database");
    $statement-&gt;bindParam(":database", $database);
    $statement-&gt;execute();
  }
  </code></pre>
  
  <p>But unfortunately, I got a PDOException saying that there is a syntax error near my binded value ($database) :</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1'</p>
  </blockquote>
  
  <p>So I tried to perform the query as follow</p>
  
  <pre><code>function delete_db($database)
  {
    $statement = $my_pdo_obj-&gt;exec("DROP DATABASE IF EXISTS " . $database);
  }
  </code></pre>
  
  <p>And it works.</p>
  
  <p>I was wondering why the prepared statement was not working and also, if the second query was secured.</p>
  
  <p>Thanks in advance for your ideas !</p>