1--TEST-- 2Interface of the class mysqli_result 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 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_all' => 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 'fetch_column' => true, 39 'field_seek' => true, 40 'free' => true, 41 'free_result' => true, 42 'getIterator' => true, 43 ); 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 $res = new mysqli_result($link); 114 115 try { 116 $res->num_rows; 117 } catch (Error $exception) { 118 echo $exception->getMessage() . "\n"; 119 } 120 121 if (!mysqli_query($link, "SELECT id FROM test ORDER BY id")) 122 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 123 124 $res = new mysqli_result($link); 125 $res = new mysqli_result($link, MYSQLI_STORE_RESULT); 126 $res = new mysqli_result($link, MYSQLI_USE_RESULT); 127 128 $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT); 129 do { 130 $mode = mt_rand(-1000, 1000); 131 } while (in_array($mode, $valid)); 132 133 if ($TEST_EXPERIMENTAL) { 134 ob_start(); 135 $res = new mysqli_result($link, $mode); 136 $content = ob_get_contents(); 137 ob_end_clean(); 138 if (!stristr($content, 'Invalid value for resultmode')) 139 printf("[009] Expecting warning because of invalid resultmode\n"); 140 } 141 142 print "done!"; 143?> 144--EXPECT-- 145Parent class: 146bool(false) 147 148Methods: 149ok 150 151Class variables: 152current_field 153field_count 154lengths 155num_rows 156type 157 158Object variables: 159 160Magic, magic properties: 161mysqli_result->current_field = '0'/integer ('0'/integer) 162mysqli_result->field_count = '2'/integer ('2'/integer) 163mysqli_result->lengths -> '1 1'/array ('1 1'/array) 164mysqli_result->num_rows = '6'/integer ('6'/integer) 165mysqli_result->type = 'store'/integer 166 167Access to undefined properties: 168mysqli_result->unknown = '' 169 170Constructor: 171mysqli_result object is already closed 172done! 173