Forum Moderators: open

Message Too Old, No Replies

mysqli interleaved queries

Getting 'Commands out of sync' error -- why?

         

directrix

11:33 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



I'm trying to use mysqli in a PHP script. I'm wondering why the following code doesn't work...

$mysqli = new mysqli('localhost', 'user', 'pw', 'db');
$stmt = $mysqli->stmt_init();
$stmt->prepare('select fld1, fld2 from filename');
$stmt->execute();
$stmt->bind_result($fld1, $fld2);

while ($stmt->fetch()) {
...
$stmt2 = $mysqli->stmt_init();
$stmt2->prepare('update filename...);

}

For brevity, I've omitted the error trapping, but the first error occurs at that second prepare call: "Commands out of sync; you can't run this command now."

Why does this error occur? Can mysqli not handle multiple statement objects for the same connection? Or am I missing something obvious?

physics

6:02 pm on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry no one replied... did you end up figuring out the error?

directrix

9:27 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



Thanks -- I've not reached a definitive conclusion, but I think it's just a limitation of the current implementation of mysqli. I've successfully done similar things before with other SQL products.