php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45763 mysqli::multi_query does not work with mysqlnd
Submitted: 2008-08-08 13:44 UTC Modified: 2008-08-11 18:06 UTC
From: michael dot kofler at gmx dot com Assigned: johannes (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.0alpha1 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael dot kofler at gmx dot com
New email:
PHP Version: OS:

 

 [2008-08-08 13:44 UTC] michael dot kofler at gmx dot com
Description:
------------
mysqli::multi_query returns FALSE if more than one query is given

Reproduce code:
---------------
$mysqli = new mysqli($mysqlhost, $mysqluser, $mysqlpasswd, $mysqldb);
$sql = "SELECT 1; SELECT 2; SELECT 3";
$ok = $mysqli->multi_query($sql);
if($ok === FALSE) {
   echo $mysqli->error();
 }


Expected result:
----------------
non (because $ok === TRUE)

(works with mysqli + libmysql)

Actual result:
--------------
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 '; SELECT 2; SELECT 3' at line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-09 00:21 UTC] johannes@php.net
Assigning to primary maintainer
 [2008-08-09 07:34 UTC] uw@php.net
Works with the procedural interface, use procedural style until fix has been committed.

Re-assigning to Johannes. Andrey is busy with non-PHP work at the moment. Johannes please have a look
 [2008-08-09 07:52 UTC] uw@php.net
Hmm, I'm wrong its more tricky. 

More like - first execution fails, second and all after work fine. It does not matter if you use the procedural or OO interface. 

The test does not catch it because it first does parameter tests (e.g. mysqli_multi_query($link, "") - expected to fail) before it runs a query. And "runs a query" is the second function call.

But anyway Johannes, if its not in the inner workings of mysqlnd itself, try to shield Andrey from PHP works.

Ulf
 [2008-08-11 07:56 UTC] michael dot kofler at gmx dot com
also does not work with PDO:

  $sql = "SELECT 1; SELECT 2; SELECT  3";
  $result = $conn->query($sql);
  do {
    echo "<p>----\n";
    $rowset = $result->fetch(PDO::FETCH_NUM);
    foreach($rowset as $row) {
      echo "<p>$row[0]";
   }
  } while($result->nextRowset());

Expected result (which I get with libmysql)

----
1
----
2
----
3

Actual result (with myslqnd, apparently only the first SQL command is evaluated)

----
1
 [2008-08-11 08:44 UTC] uw@php.net
(some debug output from my hacked php5.3 included)

nixnutz@ulflinux:~/src/php5> sapi/cli/php -i | grep configure
Configure Command =>  './configure'  '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config'

nixnutz@ulflinux:~/src/php5> sapi/cli/php -r '$p = new PDO("mysql:host=localhost;db=test", "root", "root"); $stmt = $p->query("SELECT 1; SELECT 2; SELECT 3"); do { var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); } while ($stmt->nextRowset());'
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [1]=>
    string(1) "1"
  }
}
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [2]=>
    string(1) "2"
  }
}
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [3]=>
    string(1) "3"
  }
}



nixnutz@ulflinux:~/src/php5> sapi/cli/php -i | grep configure
Configure Command =>  './configure'  '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd'

nixnutz@ulflinux:~/src/php5> sapi/cli/php -r '$p = new PDO("mysql:host=localhost;db=test", "root", "root"); $stmt = $p->query("SELECT 1; SELECT 2; SELECT 3"); do { var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); } while ($stmt->nextRowset());'
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [1]=>
    string(1) "1"
  }
}
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [2]=>
    string(1) "2"
  }
}
fetch_value(0)
param_str
array(1) {
  [0]=>
  array(1) {
    [3]=>
    string(1) "3"
  }
}
 [2008-08-11 12:45 UTC] johannes@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

The MySQLi case is fixed, the PDO case works for me with emulated prepared statements. Multi Query isn't supported by MySQL when using native prepared statements.
 [2008-08-11 18:06 UTC] michael dot kofler at gmx dot com
mysqli: works fine now, thanks!

PDO: sorry for the false alarm, another query executed before was the cause
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 18:01:31 2024 UTC