【问题标题】:General error with PDO and SQL create temporary table [duplicate]PDO 和 SQL 创建临时表的一般错误 [重复]
【发布时间】:2012-03-28 19:12:01
【问题描述】:

我正在使用 php PDO,当我使用下面的查询时出现此错误,

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 上而不是通过 PDO 查询时,它返回结果 OK。我在查询或 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]:一般错误

【问题讨论】:

  • 如果查询运行完美,它可能是正确的。你的 PDO 代码有什么问题,只有你自己知道……

标签: php mysql sql pdo create-table


【解决方案1】:

问题是您在一次调用中使用了多个查询(创建临时表,更改它,然后从中选择)。在一次通话中了解多个查询here

【讨论】:

  • 感谢您的回答。现在我知道我犯了什么错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 2015-07-29
  • 1970-01-01
  • 2016-07-26
  • 2013-06-20
  • 2017-08-20
相关资源
最近更新 更多