title: MySQL General Error 2031
body: <p>I keep getting:</p>
  
  <pre><code>Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031 ' in XXXXX
  </code></pre>
  
  <p>The code I'm using is:</p>
  
  <pre><code>$CR = $this-&gt;db-&gt;query('SELECT COUNT(*) FROM entities  WHERE (entities.typeId = 2 OR entities.typeId = 1)');
  $count = $CR-&gt;fetchColumn();
  </code></pre>
  
  <p>I have tried using prepare instead but I get the same result.</p>
  
  <p>Any idea what's causing this and how I can fix it?</p>
  
  <pre><code>class Database extends PDO {
      function __construct($user = 'xxx', $pass = 'xxx', $database = 'abc', $host = 'xxx', $port = 'xxx')
      {
              parent::__construct('mysql:host=' . $host . ';port=' . $port . ';dbname=' . $database, $user, $pass);
              $this-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              $this-&gt;setAttribute(PDO::ATTR_PERSISTENT, FALSE);
              $this-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
              $this-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
              $this-&gt;setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, TRUE);
              $this-&gt;exec("SET NAMES utf8");
      }
  }
  $this-&gt;db = new Database();
  </code></pre>