title: MySQL: error when query returns no results?
body: <p>I have a query that looks like this:</p>
  
  <pre><code>SELECT number
              FROM table1
              INNER JOIN table2
              WHERE name = 'stack_overflow' AND table1.id = table2.id
              AND user_id = 5
  </code></pre>
  
  <p>This returns a number. It does the right thing, but when inside name I pass a name that does not exist in db, PHP gives me an error. This is how I am executing it:</p>
  
  <pre><code>    $stmt = $this-&gt;db-&gt;prepare($sql);
      $stmt-&gt;execute();
  
      $x = $stmt-&gt;fetchColumn();
  </code></pre>
  
  <p>I always get the correct $x value when the name exists in the table, however when it doesn't, I get the following error:</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 'name_that_is_not_in_table'</p>
  </blockquote>
  
  <p>No idea.... </p>