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