Annotation of embedaddon/php/ext/mysqli/tests/mysqli_num_rows.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysqli_num_rows()
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifemb.inc');
7: require_once('skipifconnectfailure.inc');
8: ?>
9: --FILE--
10: <?php
11: require_once("connect.inc");
12:
13: $tmp = NULL;
14: $link = NULL;
15:
16: if (!is_null($tmp = @mysqli_num_rows()))
17: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18:
19: if (!is_null($tmp = @mysqli_num_rows($link)))
20: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21:
22: require('table.inc');
23:
24: function func_test_mysqli_num_rows($link, $query, $expected, $offset, $test_free = false) {
25:
26: if (!$res = mysqli_query($link, $query, MYSQLI_STORE_RESULT)) {
27: printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
28: return;
29: }
30:
31: if ($expected !== ($tmp = mysqli_num_rows($res)))
32: printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
33: gettype($expected), $expected,
34: gettype($tmp), $tmp);
35:
36: mysqli_free_result($res);
37:
38: if ($test_free && (NULL !== ($tmp = mysqli_num_rows($res))))
39: printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
40:
41: }
42:
43: func_test_mysqli_num_rows($link, "SELECT 1 AS a", 1, 5);
44: func_test_mysqli_num_rows($link, "SHOW VARIABLES LIKE '%nixnutz%'", 0, 10);
45: func_test_mysqli_num_rows($link, "INSERT INTO test(id, label) VALUES (100, 'z')", NULL, 15);
46: func_test_mysqli_num_rows($link, "SELECT id FROM test LIMIT 2", 2, 20, true);
47:
48: if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) {
49:
50: $row = mysqli_fetch_assoc($res);
51: mysqli_free_result($res);
52:
53: func_test_mysqli_num_rows($link, "SELECT id, label FROM test", (int)$row['num'], 25);
54:
55: } else {
56: printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57: }
58:
59: print "run_tests.php don't fool me with your 'ungreedy' expression '.+?'!\n";
60:
61: if ($res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_USE_RESULT)) {
62:
63: $row = mysqli_fetch_row($res);
64: if (0 !== ($tmp = mysqli_num_rows($res)))
65: printf("[031] Expecting int/0, got %s/%d\n", gettype($tmp), $tmp);
66:
67: mysqli_free_result($res);
68:
69: } else {
70: printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
71: }
72:
73: mysqli_close($link);
74: print "done!";
75: ?>
76: --CLEAN--
77: <?php
78: require_once("clean_table.inc");
79: ?>
80: --EXPECTF--
81: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in %s on line %d
82:
83: Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in %s on line %d
84:
85: Warning: mysqli_num_rows(): Couldn't fetch mysqli_result in %s on line %d
86: run_tests.php don't fool me with your 'ungreedy' expression '.+?'!
87:
88: Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
89: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>