mirror of
https://github.com/php/php-src.git
synced 2024-10-02 15:26:06 +00:00
a4cd950dc8
verbose explanation of changes: - take connection parameter from connect.inc - use proper UEXPECTF - have 'print "done!"' or similar at the end to detect crashes - whitespace changes where needed - take care of portability: PHP 5 vs. PHP 5, MySQL 4.1 - 6.0 - understand return value checking as sometime that makes you type more when you write but makes you happy when you debug
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
--TEST--
|
|
function test: nested selects (cursors)
|
|
--SKIPIF--
|
|
<?php
|
|
require_once('skipif.inc');
|
|
include "connect.inc";
|
|
|
|
if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
|
|
die("skip Cannot connect to check required version");
|
|
|
|
/* skip cursor test for versions < 50004 */
|
|
if ((!$IS_MYSQLND && mysqli_get_client_version() < 50009) ||
|
|
(mysqli_get_server_version($link) < 50009)) {
|
|
die(sprintf("skip Client library doesn't support cursors (%s/%s)",
|
|
mysqli_get_client_version(), mysqli_get_server_version($link));
|
|
}
|
|
mysqli_close($link);
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
function open_cursor($mysql, $query) {
|
|
if (!is_object($stmt = $mysql->prepare($query))) {
|
|
printf("[001] Cannot create statement object for '%s', [%d] %s\n",
|
|
$query, $mysql->errno, $mysql->error);
|
|
}
|
|
|
|
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY);
|
|
return $stmt;
|
|
}
|
|
|
|
include "connect.inc";
|
|
$a = array();
|
|
|
|
/*** test mysqli_connect 127.0.0.1 ***/
|
|
$mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
|
|
|
|
for ($i=0;$i < 3; $i++) {
|
|
$mysql->query("DROP TABLE IF EXISTS cursor$i");
|
|
$mysql->query("CREATE TABLE cursor$i (a int not null) ENGINE=" . $engine);
|
|
$mysql->query("INSERT INTO cursor$i VALUES (1),(2),(3),(4),(5),(6)");
|
|
$stmt[$i] = open_cursor($mysql, "SELECT a FROM cursor$i");
|
|
$stmt[$i]->execute();
|
|
$stmt[$i]->bind_result($a[$i]);
|
|
}
|
|
|
|
|
|
$cnt = 0;
|
|
while ($stmt[0]->fetch()) {
|
|
$stmt[1]->fetch();
|
|
$stmt[2]->fetch();
|
|
$cnt += $a[0] + $a[1] + $a[2];
|
|
}
|
|
|
|
for ($i=0; $i < 3; $i++) {
|
|
$stmt[$i]->close();
|
|
}
|
|
|
|
$mysql->close();
|
|
var_dump($cnt);
|
|
?>
|
|
--EXPECT--
|
|
int(63)
|