title: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in
body: <p>I have this function and it keeps giving out the error "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in..." The error is directing me to the line "$row = $q2->fetchAll(PDO::FETCH_OBJ);". I've searched tonnes for a solution but to no avail. My code appears to be the same format as the examples given in the php docs...</p>
  
  <p>Here's the function updated as per TML's suggestions:</p>
  
  <pre><code>//gets a record by id and sets object properties to it's values
  function getById($sid) {
      global $conf, $pdo;
      $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      //checks to see if a record exists for the given id
      try {
          $stmt  = $pdo-&gt;prepare('Use ' . $conf['database'] . '; select mem_id as "_id", mem_name as "_name", mem_info as "_info",
                                  mem_password as "_password", mem_email as "_email", mem_image as "_image",
                                  mem_group as "_group"
                                  from ' . $conf['prefix'] . 'members
                                  where mem_id = ?;');
          echo"85 &lt;br /&gt;";
          $stmt-&gt;execute(array($sid));
          echo"86 &lt;br /&gt;";
          $rows = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
          echo"90 &lt;br /&gt;";
          print_r($rows);
          if (count($rows) !== 1) {
              throw new Exception("Some exception here");
          }
          foreach($rows[0] as $field=&gt;$value) {
              $this-&gt;$field = $value;
              echo"97 &lt;br /&gt;";
          }
      } catch (PDOException $e) {
          echo"something went wrong! " . var_dump($e);
      }
  }
  </code></pre>
  
  <p>var_dump output:</p>
  
  <pre><code>object(PDOException)[4]
    protected 'message' =&gt; string 'SQLSTATE[HY000]: General error' (length=30)
    private 'string' (Exception) =&gt; string '' (length=0)
    protected 'code' =&gt; string 'HY000' (length=5)
    protected 'file' =&gt; string 'D:\wamp\www\testing\scripts\Kantan\classes\Member.php' (length=53)
    protected 'line' =&gt; int 86
    private 'trace' (Exception) =&gt; 
      array (size=2)
        0 =&gt; 
          array (size=6)
            'file' =&gt; string 'D:\wamp\www\testing\scripts\Kantan\classes\Member.php' (length=53)
            'line' =&gt; int 86
            'function' =&gt; string 'fetchAll' (length=8)
            'class' =&gt; string 'PDOStatement' (length=12)
            'type' =&gt; string '-&gt;' (length=2)
            'args' =&gt; 
              array (size=1)
                ...
        1 =&gt; 
          array (size=6)
            'file' =&gt; string 'D:\wamp\www\testing\scripts\Kantan\test.php' (length=43)
            'line' =&gt; int 5
            'function' =&gt; string 'getById' (length=7)
            'class' =&gt; string 'Member' (length=6)
            'type' =&gt; string '-&gt;' (length=2)
            'args' =&gt; 
              array (size=1)
                ...
    private 'previous' (Exception) =&gt; null
    public 'errorInfo' =&gt; 
      array (size=1)
        0 =&gt; string 'HY000' (length=5)
    public 'xdebug_message' =&gt; string '&lt;tr&gt;&lt;th align='left' bgcolor='#f57900' colspan="5"&gt;&lt;span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'&gt;( ! )&lt;/span&gt; PDOException: SQLSTATE[HY000]: General error in D:\wamp\www\testing\scripts\Kantan\classes\Member.php on line &lt;i&gt;86&lt;/i&gt;&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th align='left' bgcolor='#e9b96e' colspan='5'&gt;Call Stack&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;th align='center' bgcolor='#eeeeec'&gt;#&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Time&lt;/th&gt;&lt;th align='left' bgcolor='#eeeeec'&gt;Memory&lt;/th&gt;&lt;th align='left' bgcolor='#eeeee'... (length=1472)
  </code></pre>
  
  <p>Thanks in advance for any help.</p>