]> granicus.if.org Git - php/commitdiff
Fix for Bug #55582 mysqli_num_rows() returns always 0 for unbuffered, when mysqlnd...
authorAndrey Hristov <andrey@php.net>
Mon, 5 Sep 2011 15:29:45 +0000 (15:29 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 5 Sep 2011 15:29:45 +0000 (15:29 +0000)
ext/mysqli/mysqli_api.c
ext/mysqli/mysqli_libmysql.h
ext/mysqli/mysqli_mysqlnd.h
ext/mysqli/mysqli_result_iterator.c
ext/mysqli/tests/bug55582.phpt [new file with mode: 0644]
ext/mysqlnd/mysqlnd_result.c

index 041875480cd4cda73c88ca1564121aa9539c5b00..e20d963fbb4966e94a9e69da66160f279f308ab7 100644 (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);
        }
index 3ec06cdd0829f08d8567b5e9687518a1499ee56a..98e18fcfcda4e7ac98142dd68c728fe956e930f8 100644 (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)
index e4e06daeaa0408377ffd26b6865692a14138ab29..de10bb83ca429b5fd61de785bed19b12ca484d76 100644 (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))
index e49cc5d1b7708ae272653607be088e6a59e6d5b2..f1d4b68ed2330d717c56433f2be18ca01507be42 100644 (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
diff --git a/ext/mysqli/tests/bug55582.phpt b/ext/mysqli/tests/bug55582.phpt
new file mode 100644 (file)
index 0000000..85fc7f6
--- /dev/null
@@ -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
index 6262793803bc41f866494cd654a4a13b60e167ac..d4ca9c49c878962a940044f86e9129ee9d591cbf 100644 (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 */