1
0
mirror of https://github.com/php/php-src.git synced 2026-03-29 03:32:20 +02:00

Fix for Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used

This commit is contained in:
Andrey Hristov
2011-09-05 15:29:45 +00:00
parent f249361559
commit 5308ed60f3
6 changed files with 47 additions and 5 deletions

View File

@@ -1612,7 +1612,7 @@ PHP_FUNCTION(mysqli_num_rows)
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered(result)) {
if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
RETURN_LONG(0);
}

View File

@@ -30,6 +30,7 @@
/* r->data should be always NULL, at least in recent libmysql versions, the status changes once data is read*/
#define mysqli_result_is_unbuffered(r) (((r)->handle && (r)->handle->status == MYSQL_STATUS_USE_RESULT) || ((r)->data == NULL))
#define mysqli_result_is_unbuffered_and_not_everything_is_fetched(r) (((r)->handle && (r)->handle->status == MYSQL_STATUS_USE_RESULT) || ((r)->data == NULL))
#define mysqli_server_status(c) (c)->server_status
#define mysqli_stmt_get_id(s) ((s)->stmt_id)
#define mysqli_stmt_warning_count(s) mysql_warning_count((s)->mysql)

View File

@@ -31,6 +31,7 @@
#define MYSQLI_CLOSE_DISCONNECTED MYSQLND_CLOSE_DISCONNECTED
#define mysqli_result_is_unbuffered(r) ((r)->unbuf)
#define mysqli_result_is_unbuffered_and_not_everything_is_fetched(r) ((r)->unbuf && !(r)->unbuf->eof_reached)
#define mysqli_server_status(c) (c)->upsert_status.server_status
#define mysqli_stmt_get_id(s) ((s)->data->stmt_id)
#define mysqli_stmt_warning_count(s) mysqlnd_stmt_warning_count((s))

View File

@@ -133,7 +133,7 @@ static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter TSRMLS_
if (mysqli_result_is_unbuffered(result)) {
#if MYSQLI_USE_MYSQLND
if (result->unbuf && result->unbuf->eof_reached) {
if (result->unbuf->eof_reached) {
#else
if (result->eof) {
#endif

View File

@@ -0,0 +1,41 @@
--TEST--
Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
require_once("connect.inc");
?>
--FILE--
<?php
include "connect.inc";
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
printf("[001] Cannot connect to the server");
}
var_dump($link->real_query("SELECT 1"));
$res = $link->use_result();
var_dump(mysqli_num_rows($res));
var_dump($res->fetch_assoc());
var_dump(mysqli_num_rows($res));
var_dump($res->fetch_assoc());
var_dump(mysqli_num_rows($res));
$link->close();
echo "done\n";
?>
--EXPECTF--
bool(true)
Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
int(0)
array(1) {
[1]=>
string(1) "1"
}
Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
int(0)
NULL
int(1)
done

View File

@@ -601,19 +601,18 @@ mysqlnd_fetch_lengths_buffered(MYSQLND_RES * const result TSRMLS_DC)
static unsigned long *
mysqlnd_fetch_lengths_unbuffered(MYSQLND_RES * const result TSRMLS_DC)
{
return result->lengths;
/* simulate output of libmysql */
return (!result->unbuf || result->unbuf->last_row_data || result->unbuf->eof_reached)? result->lengths:NULL;
}
/* }}} */
#if !defined(MYSQLND_USE_OPTIMISATIONS) || MYSQLND_USE_OPTIMISATIONS == 0
/* {{{ mysqlnd_res::fetch_lengths */
PHPAPI unsigned long * _mysqlnd_fetch_lengths(MYSQLND_RES * const result TSRMLS_DC)
{
return result->m.fetch_lengths? result->m.fetch_lengths(result TSRMLS_CC) : NULL;
}
/* }}} */
#endif
/* {{{ mysqlnd_fetch_row_unbuffered_c */