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