1--TEST-- 2Interface of the class mysqli_result 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require('connect.inc'); 12 require('table.inc'); 13 14 $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 15 $mysqli_result = $mysqli->query('SELECT * FROM test'); 16 $row = $mysqli_result->fetch_row(); 17 18 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 19 $res = mysqli_query($link, 'SELECT * FROM test'); 20 assert(mysqli_fetch_row($res) === $row); 21 22 printf("Parent class:\n"); 23 var_dump(get_parent_class($mysqli_result)); 24 25 printf("\nMethods:\n"); 26 $methods = get_class_methods($mysqli_result); 27 $expected_methods = array( 28 '__construct' => true, 29 'close' => true, 30 'data_seek' => true, 31 'fetch_array' => true, 32 'fetch_assoc' => true, 33 'fetch_field' => true, 34 'fetch_field_direct' => true, 35 'fetch_fields' => true, 36 'fetch_object' => true, 37 'fetch_row' => true, 38 'field_seek' => true, 39 'free' => true, 40 'free_result' => true, 41 ); 42 if ($IS_MYSQLND) 43 $expected_methods['fetch_all'] = true; 44 45 foreach ($methods as $k => $method) { 46 if (isset($expected_methods[$method])) { 47 unset($expected_methods[$method]); 48 unset($methods[$k]); 49 } 50 if ($method == 'mysqli_result') { 51 // get_class_method reports different constructor names 52 unset($expected_methods['__construct']); 53 unset($methods[$k]); 54 } 55 } 56 57 if (!empty($expected_methods)) { 58 printf("Dumping list of missing methods.\n"); 59 var_dump($expected_methods); 60 } 61 if (!empty($methods)) { 62 printf("Dumping list of unexpected methods.\n"); 63 var_dump($methods); 64 } 65 if (empty($expected_methods) && empty($methods)) 66 printf("ok\n"); 67 68 69 printf("\nClass variables:\n"); 70 $variables = array_keys(get_class_vars(get_class($mysqli_result))); 71 sort($variables); 72 foreach ($variables as $k => $var) 73 printf("%s\n", $var); 74 75 printf("\nObject variables:\n"); 76 $variables = array_keys(get_object_vars($mysqli_result)); 77 foreach ($variables as $k => $var) 78 printf("%s\n", $var); 79 80 printf("\nMagic, magic properties:\n"); 81 82 assert(($tmp = mysqli_field_tell($res)) === $mysqli_result->current_field); 83 printf("mysqli_result->current_field = '%s'/%s ('%s'/%s)\n", 84 $mysqli_result->current_field, gettype($mysqli_result->current_field), 85 $tmp, gettype($tmp)); 86 87 assert(($tmp = mysqli_field_count($link)) === $mysqli_result->field_count); 88 printf("mysqli_result->field_count = '%s'/%s ('%s'/%s)\n", 89 $mysqli_result->field_count, gettype($mysqli_result->field_count), 90 $tmp, gettype($tmp)); 91 92 assert(($tmp = mysqli_fetch_lengths($res)) === $mysqli_result->lengths); 93 printf("mysqli_result->lengths -> '%s'/%s ('%s'/%s)\n", 94 ((is_array($mysqli_result->lengths)) ? implode(' ', $mysqli_result->lengths) : 'n/a'), 95 gettype($mysqli_result->lengths), 96 ((is_array($tmp)) ? implode(' ', $tmp) : 'n/a'), 97 gettype($tmp)); 98 99 assert(($tmp = mysqli_num_rows($res)) === $mysqli_result->num_rows); 100 printf("mysqli_result->num_rows = '%s'/%s ('%s'/%s)\n", 101 $mysqli_result->num_rows, gettype($mysqli_result->num_rows), 102 $tmp, gettype($tmp)); 103 104 assert(in_array($mysqli_result->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT))); 105 printf("mysqli_result->type = '%s'/%s\n", 106 ((MYSQLI_STORE_RESULT == $mysqli_result->type) ? 'store' : 'use'), 107 gettype($mysqli_result->type)); 108 109 printf("\nAccess to undefined properties:\n"); 110 printf("mysqli_result->unknown = '%s'\n", @$mysqli_result->unknown); 111 112 printf("\nConstructor:\n"); 113 if (!is_object($res = new mysqli_result($link))) 114 printf("[001] Expecting object/mysqli_result got %s/%s\n", gettye($res), $res); 115 116 if (null !== ($tmp = @$res->num_rows)) 117 printf("[002] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 118 119 if (!mysqli_query($link, "SELECT id FROM test ORDER BY id")) 120 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 121 122 if (!is_object($res = new mysqli_result($link))) 123 printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 124 125 if (!is_object($res = new mysqli_result($link, MYSQLI_STORE_RESULT))) 126 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 127 128 if (!is_object($res = new mysqli_result($link, MYSQLI_USE_RESULT))) 129 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 130 131 if (!is_object($res = new mysqli_result($link, 'invalid'))) 132 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 133 134 $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT); 135 do { 136 $mode = mt_rand(-1000, 1000); 137 } while (in_array($mode, $valid)); 138 139 if ($TEST_EXPERIMENTAL) { 140 ob_start(); 141 if (!is_object($res = new mysqli_result($link, $mode))) 142 printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 143 $content = ob_get_contents(); 144 ob_end_clean(); 145 if (!stristr($content, 'Invalid value for resultmode')) 146 printf("[009] Expecting warning because of invalid resultmode\n"); 147 } 148 149 if (!is_object($res = new mysqli_result('foo'))) 150 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 151 152 if (!is_object($res = @new mysqli_result($link, MYSQLI_STORE_RESULT, 1))) 153 printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 154 155 print "done!"; 156?> 157--EXPECTF-- 158Parent class: 159bool(false) 160 161Methods: 162ok 163 164Class variables: 165current_field 166field_count 167lengths 168num_rows 169type 170 171Object variables: 172current_field 173field_count 174lengths 175num_rows 176type 177 178Magic, magic properties: 179mysqli_result->current_field = '0'/integer ('0'/integer) 180mysqli_result->field_count = '2'/integer ('2'/integer) 181mysqli_result->lengths -> '1 1'/array ('1 1'/array) 182mysqli_result->num_rows = '6'/integer ('6'/integer) 183mysqli_result->type = 'store'/integer 184 185Access to undefined properties: 186mysqli_result->unknown = '' 187 188Constructor: 189 190Warning: mysqli_result::__construct() expects parameter 2 to be integer, %unicode_string_optional% given in %s on line %d 191 192Warning: mysqli_result::__construct() expects parameter 1 to be mysqli, %unicode_string_optional% given in %s on line %d 193done! 194