2012-03-12 109 views
0

我使用PHP PDO,當我使用下面的查詢我有這樣的錯誤,與PDO和SQL一般錯誤創建臨時表

SQLSTATE[HY000]: General error 

查詢,

  CREATE TEMPORARY TABLE temp_tb 
      SELECT * FROM person; 

      ALTER TABLE temp_tb 
      DROP type; 
      SELECT * 
      FROM temp_tb AS p 

      LEFT JOIN user AS u 
      ON p.person_id = u.person_id 

      LEFT JOIN category AS c 
      ON u.category_id = c.category_id 

      WHERE u.signature = ? 

他們查詢創建一個臨時表,然後從該臨時表中刪除一列,然後將其與其他表加入。

當我直接在phpMyAdmin上查詢時返回結果OK,但不是通過PDO。我在查詢或PDO中做了錯誤的事情?我該如何解決這個問題?

編輯:

PDO,

public function fetch_object($query, $params = array()) 
    { 
     try 
     { 
      # prepare the query 
      $stmt = $this->connection->prepare($query); 

      # if $params is not an array, let's make it array with one value of former $params 
      if (!is_array($params)) $params = array($params); 

      # execute the query 
      $stmt->execute($params); 

      # return the result 
      return $stmt->fetchObject(); 
      //return $stmt->fetch(PDO::FETCH_OBJ); 
     } 
     catch (PDOException $e) 
     { 
      # call the get_error function 
      $this->get_error($e); 
     } 
    } 

$user = $this->database->fetch_object($sql,$authenticated_user); 

錯誤,

SQLSTATE [HY000]:常規錯誤

+0

查詢可能是正確的,如果它運行完美無缺。無論您的PDO代碼有什麼問題,只有您可以知道... – 2012-03-12 11:36:42

回答

0

的問題是,你在一個呼叫使用多個查詢(創建臨時表,改變它然後從中選擇)。在一次調用中瞭解多個查詢here

+0

感謝您的回答。現在我知道我做了什麼錯誤。 – laukok 2012-03-12 13:43:14