title: "SQLSTATE[HY000]: General error" - Multiple SQL queries in one statement
body: <p>I have a query in my php script that is handled by PDO. To be exact it's 2 queries in 1 statement. The query itself runs fine in SQL client (I'm using HeidiSQL). PHP however gives me exactly this error: "<strong>SQLSTATE[HY000]: General error</strong>" with nothing else. No error number or message. </p>
  
  <p>Is there a way to debug the query somehow? I don't think there's an error in query itself, so I don't know what's wrong. Nothing shows in mysql error log. I've enabled mysql general log, but it only logs query itself without showing an error.</p>
  
  <p>My stack: XAMPP 1.8, Apache 2.4.3, PHP 5.4.7, MySQL 5.5.27</p>
  
  <p>This is my query (it's rather long):</p>
  
  <pre><code>    /*First query - generating temp table with overdue jobs*/
  
      CREATE TEMPORARY TABLE temp AS (
          SELECT  j.NetworkID,
              @clientID := j.ClientID,
              j.BranchID,
              j.ServiceProviderID,
              (   
                  (DATEDIFF(CURDATE(), j.DateBooked)) 
                  - 
                  IF(
                  (@unit :=   (
                      SELECT      uctype.UnitTurnaroundTime
                      FROM        job
                      LEFT JOIN   product ON job.ProductID = product.ProductID
                      LEFT JOIN   unit_type AS utype ON product.UnitTypeID = utype.UnitTypeID
                      LEFT JOIN   unit_client_type AS uctype 
                              ON utype.UnitTypeID = uctype.UnitTypeID 
                              AND uctype.ClientID = @clientID
                      WHERE       job.JobID = j.JobID
                      )
                  ) IS NOT NULL,      /*statement*/
                  @unit,          /*TRUE - Client Unit Type has turnaround time assigned in the db*/  
                  IF(         /*FALSE - Now checking if Client Default Turnaround Time is set*/
                      (@clnt := (
                          SELECT  DefaultTurnaroundTime AS dtt
                          FROM    client
                          WHERE   client.ClientID = @clientID
                      )
                      ) IS NOT NULL,  /*statement*/
                      @clnt,      /*TRUE - Client Default Turaround time is set*/
                      (           /*FALSE - falling back to general default*/
                      SELECT  gen.Default
                      FROM    general_default AS gen
                      WHERE   gen.GeneralDefaultID = 1
                      )
                  )
                  )
              ) AS overdue
  
          FROM    job AS j
  
          HAVING  overdue &gt; 0
      );
  
  
      /*Second query - filtering out overdue jobs with specific time range*/
  
      SELECT  COUNT(*) AS number
      FROM    temp
      WHERE   overdue &gt;= :from AND overdue &lt;= :to AND overdue != 0
  </code></pre>
  
  <p><strong>UPDATE:</strong> The problem seems to be caused by PDO refusing to run several queries in one statement. I've inserted this before executing query:</p>
  
  <pre><code>$conn-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
  </code></pre>
  
  <p>So now "General error" is gone, but I'm getting </p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
  </code></pre>
  
  <p>just after the first query, meaning that PDO just runs one query and refuses to continue...</p>