1--TEST-- 2mysqli_fetch_field() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require_once("connect.inc"); 11 12 // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test 13 $mysqli = new mysqli(); 14 $res = false; 15 try { 16 new mysqli_result($mysqli); 17 } catch (Error $exception) { 18 echo $exception->getMessage() . "\n"; 19 } 20 21 require('table.inc'); 22 if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket)) 23 printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 24 $host, $user, $db, $port, $socket); 25 26 // Make sure that client, connection and result charsets are all the 27 // same. Not sure whether this is strictly necessary. 28 if (!$mysqli->set_charset('utf8')) 29 printf("[%d] %s\n", $mysqli->errno, $mysqli->errno); 30 31 $charsetInfo = $mysqli->get_charset(); 32 33 if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { 34 printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); 35 } 36 37 var_dump($res->fetch_field()); 38 39 $tmp = $res->fetch_field(); 40 var_dump($tmp); 41 if ($tmp->charsetnr != $charsetInfo->number) { 42 printf("[005] Expecting charset %s/%d got %d\n", 43 $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr); 44 } 45 if ($tmp->length != $charsetInfo->max_length) { 46 printf("[006] Expecting length %d got %d\n", 47 $charsetInfo->max_length, $tmp->max_length); 48 } 49 if ($tmp->db != $db) { 50 printf("[007] Expecting database '%s' got '%s'\n", 51 $db, $tmp->db); 52 } 53 54 var_dump($res->fetch_field()); 55 56 $res->free_result(); 57 58 try { 59 $res->fetch_field(); 60 } catch (Error $exception) { 61 echo $exception->getMessage() . "\n"; 62 } 63 64 $mysqli->close(); 65 print "done!"; 66?> 67--CLEAN-- 68<?php 69 require_once("clean_table.inc"); 70?> 71--EXPECTF-- 72mysqli object is not fully initialized 73object(stdClass)#%d (13) { 74 ["name"]=> 75 string(2) "ID" 76 ["orgname"]=> 77 string(2) "id" 78 ["table"]=> 79 string(4) "TEST" 80 ["orgtable"]=> 81 string(4) "test" 82 ["def"]=> 83 string(0) "" 84 ["db"]=> 85 string(%d) "%s" 86 ["catalog"]=> 87 string(%d) "%s" 88 ["max_length"]=> 89 int(1) 90 ["length"]=> 91 int(11) 92 ["charsetnr"]=> 93 int(63) 94 ["flags"]=> 95 int(49155) 96 ["type"]=> 97 int(3) 98 ["decimals"]=> 99 int(0) 100} 101object(stdClass)#%d (13) { 102 ["name"]=> 103 string(5) "label" 104 ["orgname"]=> 105 string(5) "label" 106 ["table"]=> 107 string(4) "TEST" 108 ["orgtable"]=> 109 string(4) "test" 110 ["def"]=> 111 string(0) "" 112 ["db"]=> 113 string(%d) "%s" 114 ["catalog"]=> 115 string(%d) "%s" 116 ["max_length"]=> 117 int(%d) 118 ["length"]=> 119 int(%d) 120 ["charsetnr"]=> 121 int(%d) 122 ["flags"]=> 123 int(0) 124 ["type"]=> 125 int(254) 126 ["decimals"]=> 127 int(0) 128} 129bool(false) 130mysqli_result object is already closed 131done! 132