1--TEST-- 2mysqli_num_rows() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11 require 'table.inc'; 12 13 function func_test_mysqli_num_rows($link, $query, $expected, $offset, $test_free = false) { 14 15 if (!$res = mysqli_query($link, $query, MYSQLI_STORE_RESULT)) { 16 printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); 17 return; 18 } 19 20 if (!is_bool($res)) { 21 if ($expected !== ($tmp = mysqli_num_rows($res))) 22 printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1, 23 gettype($expected), $expected, 24 gettype($tmp), $tmp); 25 26 mysqli_free_result($res); 27 28 try { 29 mysqli_num_rows($res); 30 } catch (Error $exception) { 31 echo $exception->getMessage() . "\n"; 32 } 33 } 34 } 35 36 func_test_mysqli_num_rows($link, "SELECT 1 AS a", 1, 5); 37 func_test_mysqli_num_rows($link, "SHOW VARIABLES LIKE '%nixnutz%'", 0, 10); 38 func_test_mysqli_num_rows($link, "INSERT INTO test(id, label) VALUES (100, 'z')", NULL, 15); 39 func_test_mysqli_num_rows($link, "SELECT id FROM test LIMIT 2", 2, 20, true); 40 41 if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) { 42 43 $row = mysqli_fetch_assoc($res); 44 mysqli_free_result($res); 45 46 func_test_mysqli_num_rows($link, "SELECT id, label FROM test", (int)$row['num'], 25); 47 48 } else { 49 printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 50 } 51 52 print "run_tests.php don't fool me with your 'ungreedy' expression '.+?'!\n"; 53 54 if ($res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_USE_RESULT)) { 55 56 $row = mysqli_fetch_row($res); 57 try { 58 var_dump(mysqli_num_rows($res)); 59 } catch (\Error $e) { 60 echo $e->getMessage() . \PHP_EOL; 61 } 62 63 mysqli_free_result($res); 64 } else { 65 printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 66 } 67 68 mysqli_close($link); 69 print "done!"; 70?> 71--CLEAN-- 72<?php 73 require_once 'clean_table.inc'; 74?> 75--EXPECT-- 76mysqli_result object is already closed 77mysqli_result object is already closed 78mysqli_result object is already closed 79mysqli_result object is already closed 80run_tests.php don't fool me with your 'ungreedy' expression '.+?'! 81mysqli_num_rows() cannot be used in MYSQLI_USE_RESULT mode 82done! 83