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