title: Executing huge query returns SQLSTATE[HY000]: General error
body: <p>There is no further description of the error, the error above is the only thing that I'm getting. I also managed to get line of the error, and it is the one where I try to fetchAll results.</p>
  
  <pre><code>$id = (int) base64_decode($id);
  try {
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $conn-&gt;beginTransaction();
      $sql = "SET @i:=0; SELECT result.* FROM (SELECT @x:=@x+1 AS position, temp.* FROM (SELECT u.id, u.fbname, MAX( c.likeit + c.loveit + c.cute + c.aw ) AS total, c.likeit, c.loveit, c.cute, c.aw FROM currentphoto AS c LEFT JOIN users AS u ON u.id = c.id GROUP BY u.id ORDER BY total DESC) temp ) result WHERE id = :id";
      $stmt = $conn-&gt;prepare($sql);
      $stmt-&gt;bindParam(':id', $id, PDO::PARAM_INT);
      $stmt-&gt;execute();
      $rows = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
      $conn-&gt;commit();
  } catch (Exception $e) {
      $conn-&gt;rollBack();
      echo $e-&gt;getMessage();
  }
  if ($rows != null) {
      return json_encode(base64_encode($rows));
  } else return null;
  </code></pre>
  
  <p>I just read somewhere that using mysql variables in PDO might require using declarations in separate queries. Is that right? And if so, how do I do it? Do I execute first statement with variable and the second statement after that?</p>
  
  <p>If that isnt right, then what is the problem? Thanks guys</p>