summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2011-09-05 15:29:45 +0000
committerAndrey Hristov <andrey@php.net>2011-09-05 15:29:45 +0000
commit4325a8bffcf6768297a8fa186bbace4f879ba951 (patch)
treece9c45b51014b7809ac37aabe97178b7bc21d330
parent67872cf7a90828e9424c2cca7271715e6c710339 (diff)
downloadphp-git-4325a8bffcf6768297a8fa186bbace4f879ba951.tar.gz
Fix for Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd is used
-rw-r--r--ext/mysqli/mysqli_api.c2
-rw-r--r--ext/mysqli/mysqli_libmysql.h1
-rw-r--r--ext/mysqli/mysqli_mysqlnd.h1
-rw-r--r--ext/mysqli/mysqli_result_iterator.c2
-rw-r--r--ext/mysqli/tests/bug55582.phpt41
-rw-r--r--ext/mysqlnd/mysqlnd_result.c5
6 files changed, 47 insertions, 5 deletions
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 041875480c..e20d963fbb 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -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);
}
diff --git a/ext/mysqli/mysqli_libmysql.h b/ext/mysqli/mysqli_libmysql.h
index 3ec06cdd08..98e18fcfcd 100644
--- a/ext/mysqli/mysqli_libmysql.h
+++ b/ext/mysqli/mysqli_libmysql.h
@@ -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)
diff --git a/ext/mysqli/mysqli_mysqlnd.h b/ext/mysqli/mysqli_mysqlnd.h
index e4e06daeaa..de10bb83ca 100644
--- a/ext/mysqli/mysqli_mysqlnd.h
+++ b/ext/mysqli/mysqli_mysqlnd.h
@@ -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))
diff --git a/ext/mysqli/mysqli_result_iterator.c b/ext/mysqli/mysqli_result_iterator.c
index e49cc5d1b7..f1d4b68ed2 100644
--- a/ext/mysqli/mysqli_result_iterator.c
+++ b/ext/mysqli/mysqli_result_iterator.c
@@ -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
diff --git a/ext/mysqli/tests/bug55582.phpt b/ext/mysqli/tests/bug55582.phpt
new file mode 100644
index 0000000000..85fc7f6ce8
--- /dev/null
+++ b/ext/mysqli/tests/bug55582.phpt
@@ -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 \ No newline at end of file
diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c
index 6262793803..d4ca9c49c8 100644
--- a/ext/mysqlnd/mysqlnd_result.c
+++ b/ext/mysqlnd/mysqlnd_result.c
@@ -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 */