Bug #70786 [NEW]: mysqli_stmt objects can not be processed in the nested iterations

From: Date: Sun, 25 Oct 2015 20:08:33 +0000
Subject: Bug #70786 [NEW]: mysqli_stmt objects can not be processed in the nested iterations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196800@lists.php.net to get a copy of this message
From:             it_poz at interia dot eu
Operating system: MS Windows Vista Business 64-bit
PHP version:      7.0.0RC5
Package:          MySQLi related
Bug Type:         Bug
Bug description:mysqli_stmt objects can not be processed in the nested iterations

Description:
------------
The environment:
MS Win Vista Business 64-bit, MySQL 5.6.26, PHP 7.0RC5 on IIS 7.0 via
FastCGI, mysqli ext installed.


The mysqli_stmt objects can not be processed in the nested iterations
– looks like, they influence to each other.

Probably the second mysqli_stmt object (see the example script)
doesn’t work at all due to some collision to the first one.
Same problem I have observed in the earlier PHP versions like PHP
5.6.14, 5.5.30, 5.4.45 and 5.3.29.

In the example I have used the SELECT query, but even more strange
behavior have been noticed for the other statement queries like UPDATE
or INSERT and it is very difficult find the reason of that (see the
debug info in the example code).



Similar task, but realized within the MySQL client (5.6.26 for MS
Windows) works well and as expected. It is possible to PREPARE and
EXECUTE prepared statements in any order and the defined statements can
coexist and don’t influence to each other.

Test script:
---------------
Let’s consider very simple example of two tables in the data base
(MySQL):

tbl_1
---------------------------
| id_tbl_1 |  name_tbl_1  |
---------------------------
|      1   |     ntbl1_1  |
|      2   |     ntbl1_2  |
---------------------------

tbl_2
---------------------------
| id_tbl_2 |  name_tbl_2  |
---------------------------
|      1   |     ntbl2_1  |
|      2   |     ntbl2_2  |
---------------------------

It doesn’t matter whether the tables are somehow related or not.


The PHP code:

// the MySQL connection is established and is correct for the right user
with adequate privileges – the connection handler is $db_res

$stmt_1 = $db_res->stmt_init();
$stmt_1->prepare('SELECT name_tbl_1 FROM tbl_1 WHERE id_tbl_1 = ?');
$stmt_2 = $db_res->stmt_init();
$stmt_2->prepare('SELECT name_tbl_2 FROM tbl_2 WHERE id_tbl_2 = ?');

for ($i = 1; $i <= 2; $i++) {
  $stmt_1->bind_param('i', $i);      // returns TRUE here
  $stmt_1->execute();                // returns TRUE here
  $stmt_1->bind_result($name_1);     // returns TRUE here
  $stmt_1->fetch();                  // returns TRUE here
  echo $name_1.'<br />';
  for ($j = 1; $j <= 2; $j++) {
    $stmt_2->bind_param('i', $j);    // returns TRUE here
    $stmt_2->execute();              // returns TRUE here
    $stmt_2->bind_result($name_2);   // returns TRUE here
    $stmt_2->fetch();                // returns FALSE here
    echo '------'.$name_2.'<br />';
  }
}
$stmt_1->close();
$stmt_2->close();

// close data base connection

Expected result:
----------------
The expected result should be something like that:

ntbl1_1
------ntbl2_1
------ntbl2_2
ntbl1_2
------ntbl2_1
------ntbl2_2

Actual result:
--------------
but the received result, unfortunately is like that:

ntbl1_1
------
------
ntbl1_2
------
------

-- 
Edit bug report at https://bugs.php.net/bug.php?id=70786&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70786&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70786&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70786&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70786&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70786&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70786&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70786&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70786&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70786&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70786&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70786&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70786&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70786&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70786&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70786&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70786&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70786&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70786&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70786&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70786&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#196800) next »