1--TEST-- 2Interface of the class mysqli_result 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require('connect.inc'); 11 require('table.inc'); 12 13 $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 14 $mysqli_result = $mysqli->query('SELECT * FROM test'); 15 $row = $mysqli_result->fetch_row(); 16 17 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 18 $res = mysqli_query($link, 'SELECT * FROM test'); 19 assert(mysqli_fetch_row($res) === $row); 20 21 printf("Parent class:\n"); 22 var_dump(get_parent_class($mysqli_result)); 23 24 printf("\nMethods:\n"); 25 $methods = get_class_methods($mysqli_result); 26 $expected_methods = array( 27 '__construct' => true, 28 'close' => true, 29 'data_seek' => true, 30 'fetch_array' => true, 31 'fetch_assoc' => true, 32 'fetch_field' => true, 33 'fetch_field_direct' => true, 34 'fetch_fields' => true, 35 'fetch_object' => true, 36 'fetch_row' => true, 37 'field_seek' => true, 38 'free' => true, 39 'free_result' => true, 40 'getIterator' => 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 try { 117 $res->num_rows; 118 } catch (Error $exception) { 119 echo $exception->getMessage() . "\n"; 120 } 121 122 if (!mysqli_query($link, "SELECT id FROM test ORDER BY id")) 123 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 124 125 if (!is_object($res = new mysqli_result($link))) 126 printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 127 128 if (!is_object($res = new mysqli_result($link, MYSQLI_STORE_RESULT))) 129 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 130 131 if (!is_object($res = new mysqli_result($link, MYSQLI_USE_RESULT))) 132 printf("[006] [%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 print "done!"; 150?> 151--EXPECT-- 152Parent class: 153bool(false) 154 155Methods: 156ok 157 158Class variables: 159current_field 160field_count 161lengths 162num_rows 163type 164 165Object variables: 166current_field 167field_count 168lengths 169num_rows 170type 171 172Magic, magic properties: 173mysqli_result->current_field = '0'/integer ('0'/integer) 174mysqli_result->field_count = '2'/integer ('2'/integer) 175mysqli_result->lengths -> '1 1'/array ('1 1'/array) 176mysqli_result->num_rows = '6'/integer ('6'/integer) 177mysqli_result->type = 'store'/integer 178 179Access to undefined properties: 180mysqli_result->unknown = '' 181 182Constructor: 183mysqli_result object is already closed 184done! 185