1--TEST-- 2mysqli_fetch_field() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test 17 $mysqli = new mysqli(); 18 $res = @new mysqli_result($mysqli); 19 if (!is_null($tmp = @$res->fetch_field())) 20 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 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 if (!is_null($tmp = @$res->fetch_field($link))) 28 printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 29 30 $charsets = my_get_charsets($link); 31 32 if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { 33 printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); 34 } 35 36 var_dump($res->fetch_field()); 37 38 $tmp = $res->fetch_field(); 39 var_dump($tmp); 40 if ($tmp->charsetnr != $charsets['results']['nr']) { 41 printf("[005] Expecting charset %s/%d got %d\n", 42 $charsets['results']['charset'], 43 $charsets['results']['nr'], $tmp->charsetnr); 44 } 45 if ($tmp->length != (1 * $charsets['results']['maxlen'])) { 46 printf("[006] Expecting length %d got %d\n", 47 $charsets['results']['maxlen'], 48 $tmp->max_length); 49 } 50 if ($tmp->db != $db) { 51 printf("008] Expecting database '%s' got '%s'\n", 52 $db, $tmp->db); 53 } 54 55 var_dump($res->fetch_field()); 56 57 $res->free_result(); 58 59 if (NULL !== ($tmp = $res->fetch_field())) 60 printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 61 62 $mysqli->close(); 63 print "done!"; 64?> 65--CLEAN-- 66<?php 67 require_once("clean_table.inc"); 68?> 69--EXPECTF-- 70object(stdClass)#%d (13) { 71 [%u|b%"name"]=> 72 %unicode|string%(2) "ID" 73 [%u|b%"orgname"]=> 74 %unicode|string%(2) "id" 75 [%u|b%"table"]=> 76 %unicode|string%(4) "TEST" 77 [%u|b%"orgtable"]=> 78 %unicode|string%(4) "test" 79 [%u|b%"def"]=> 80 %unicode|string%(0) "" 81 [%u|b%"db"]=> 82 %unicode|string%(%d) "%s" 83 [%u|b%"catalog"]=> 84 %unicode|string%(%d) "%s" 85 [%u|b%"max_length"]=> 86 int(1) 87 [%u|b%"length"]=> 88 int(11) 89 [%u|b%"charsetnr"]=> 90 int(63) 91 [%u|b%"flags"]=> 92 int(49155) 93 [%u|b%"type"]=> 94 int(3) 95 [%u|b%"decimals"]=> 96 int(0) 97} 98object(stdClass)#%d (13) { 99 [%u|b%"name"]=> 100 %unicode|string%(5) "label" 101 [%u|b%"orgname"]=> 102 %unicode|string%(5) "label" 103 [%u|b%"table"]=> 104 %unicode|string%(4) "TEST" 105 [%u|b%"orgtable"]=> 106 %unicode|string%(4) "test" 107 [%u|b%"def"]=> 108 %unicode|string%(0) "" 109 [%u|b%"db"]=> 110 %unicode|string%(%d) "%s" 111 [%u|b%"catalog"]=> 112 %unicode|string%(%d) "%s" 113 [%u|b%"max_length"]=> 114 int(%d) 115 [%u|b%"length"]=> 116 int(%d) 117 [%u|b%"charsetnr"]=> 118 int(%d) 119 [%u|b%"flags"]=> 120 int(0) 121 [%u|b%"type"]=> 122 int(254) 123 [%u|b%"decimals"]=> 124 int(0) 125} 126bool(false) 127 128Warning: mysqli_result::fetch_field(): Couldn't fetch mysqli_result in %s on line %d 129done!