1--TEST-- 2mysqli_fetch_column() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11require 'table.inc'; 12mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); 13 14$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1"); 15 16print "[001]\n"; 17var_dump(mysqli_fetch_column($res)); 18 19print "[002]\n"; 20var_dump(mysqli_fetch_column($res)); 21 22 23$link->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true); 24 25$res = mysqli_query($link, "SELECT 26 1 AS a, 27 2 AS a 28"); 29print "[003]\n"; 30var_dump(mysqli_fetch_column($res, 0)); 31 32$res = mysqli_query($link, "SELECT 33 1 AS a, 34 2 AS a 35"); 36print "[004]\n"; 37var_dump(mysqli_fetch_column($res, 1)); 38 39$res = mysqli_query($link, "SELECT 40 1 AS a, 41 2 AS a, 42 3 43"); 44print "[005]\n"; 45var_dump(mysqli_fetch_column($res, 2)); 46 47$res = mysqli_query($link, "SELECT 48 1 AS a, 49 2 AS a, 50 3, 51 NULL AS d 52"); 53print "[006]\n"; 54var_dump(mysqli_fetch_column($res, 3)); 55 56$res = mysqli_query($link, "SELECT 57 1 AS a, 58 2 AS a, 59 3, 60 NULL AS d, 61 true AS e 62"); 63print "[007]\n"; 64var_dump(mysqli_fetch_column($res, 4)); 65 66$res = mysqli_query($link, "SELECT 67 1.42 AS a 68"); 69print "[008]\n"; 70var_dump(mysqli_fetch_column($res, 0)); 71 72$res = mysqli_query($link, "SELECT 73 1.42E0 AS a 74"); 75print "[009]\n"; 76var_dump(mysqli_fetch_column($res, 0)); 77 78$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1"); 79print "[010]\n"; 80try { 81 var_dump(mysqli_fetch_column($res, -1)); 82} catch (\ValueError $e) { 83 echo $e->getMessage(), \PHP_EOL; 84} 85 86$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1"); 87print "[011]\n"; 88try { 89 var_dump(mysqli_fetch_column($res, 2)); 90} catch (\ValueError $e) { 91 echo $e->getMessage(), \PHP_EOL; 92} 93 94mysqli_free_result($res); 95try { 96 mysqli_fetch_column($res); 97} catch (Error $exception) { 98 echo $exception->getMessage() . "\n"; 99} 100 101$res = $link->query("SELECT id, label FROM test ORDER BY id LIMIT 2"); 102 103print "[012]\n"; 104var_dump($res->fetch_column()); 105 106print "[013]\n"; 107var_dump($res->fetch_column(1)); 108 109mysqli_close($link); 110?> 111--CLEAN-- 112<?php 113require_once 'clean_table.inc'; 114?> 115--EXPECT-- 116[001] 117string(1) "1" 118[002] 119bool(false) 120[003] 121int(1) 122[004] 123int(2) 124[005] 125int(3) 126[006] 127NULL 128[007] 129int(1) 130[008] 131string(4) "1.42" 132[009] 133float(1.42) 134[010] 135mysqli_fetch_column(): Argument #2 ($column) must be greater than or equal to 0 136[011] 137mysqli_fetch_column(): Argument #2 ($column) must be less than the number of fields for this result set 138mysqli_result object is already closed 139[012] 140int(1) 141[013] 142string(1) "b" 143