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