Ejecute multiple SQL statements in PEAR::DB
| From: | Federico Petronio | Date: | Thu, 16 Mar 2006 14:39:25 +0000 |
| Subject: | Ejecute multiple SQL statements in PEAR::DB | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-23307@lists.php.net to get a copy of this message | ||
Hello,
I am trying to execute multiple SQL statements in only 1 query, but I
just can't figure out how (if it is possible) to do it.
For example, I'd like to execute:
DELETE FROM table1 WHERE <...> ; DELETE FROM table2 WHERE <...>
Is there a way to do that with PEAR (mysql as SQL backend)? If I use
this code:
$sql="SELECT @client_id:=$client_id; DELETE FROM transaction WHERE
client_id = @client_id";
$db = DB::connect(mysql://$dbuser:$dbpass@$dbhost/$dbname");
$r = $db->query($sql);
I get:
'SELECT @client_id:=100050; DELETE FROM transaction WHERE client_id =
@client_id [nativecode=1064 ** You have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server version for the
right syntax to use near '; DELETE FROM transaction WHERE client_id =
@client_id' at line]'
But I don't think MySQL has problems with it, if I run it in the CLI it
works out fine.
Thank you!
Federico Petronio