9

I am unable to execut long script the pdo throws an exception:

SQLSTATE[HY000]: General error

If I submit script which does not contain variables it runs w/o problem. The same script runs on phpmyadmin interface.

Here is my code snippet:

 try {
 $dsn = "mysql:host=" . DB_SERVER . ";dbname=" . DB_DEFAULT;
 $db = new PDO($dsn, DB_USER, DB_PASS);
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $q = $db->query($query);
 if (!$q) {
 echo $db->errorInfo();
  } else {
        $rows = $q->fetchAll(PDO::FETCH_ASSOC);
    }
} catch (PDOException $e) {
    var_dump($e);
 }

Here is some test which does not execute by PDO:

SET @ra_LMC:=80.9;
SELECT @ra_LMC;

How I should execut with pdo the multi line scripts?

Thanks
Arman.

2
  • Can we see what your query looks like? Commented Jan 13, 2011 at 19:18
  • The query fails if any "set" operator is exist.as written in example. Commented Jan 13, 2011 at 19:37

2 Answers 2

14

PDO does not allow the execution of multiple statements in one query() request. But your @ra_LMC variable should be visible in the current connection, so you can put your second line (SELECT) into a new query() call.

To read a whole script, you have to parse the file and run each statement with a call to query().

Sign up to request clarification or add additional context in comments.

Comments

7

PDO can only execute one statement at a time. You can ether run the SET and SELECT as 2 separate statements. Or you can set the variable using FROM.

SELECT @ra_LMC FROM (SELECT @ra_LMC:=80.9) q

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.