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