0

I am using php PDO and I have this error when I use the query below,

SQLSTATE[HY000]: General error

query,

            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 = ?

They query is to create a temp table and then to drop a column from that temp table, then join it with other tables.

It returns result OK when I query it directly on phpMyAdmin but not through PDO. Something I have done wrong in the query or the PDO? How can I get around to this?

EDIT:

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);

error,

SQLSTATE[HY000]: General error

hakre
  • 193,403
  • 52
  • 435
  • 836
Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

2

The problem is that you use several queries in one call (create temp table, alter it and then select from it). Read about multiple queries in one call here

Community
  • 1
  • 1
a.tereschenkov
  • 807
  • 4
  • 10