Skip to content

Commit 970d659

Browse files
Fix libmysql test cases (#7097)
Fixed test cases for: mysqli_stmt_execute_bind_libmysql, bug77935, fetch_column, and some others that failed on libmysql
1 parent 182e3ac commit 970d659

File tree

6 files changed

+164
-25
lines changed

6 files changed

+164
-25
lines changed

ext/mysqli/tests/bug77935.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ mysqli
55
--SKIPIF--
66
<?php
77
require_once('skipifconnectfailure.inc');
8+
if (!$IS_MYSQLND) {
9+
die("skip mysqlnd only test");
10+
}
811
?>
912
--FILE--
1013
<?php

ext/mysqli/tests/deprecated_constants.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ echo constant('MYSQLI_NO_DATA')."\n";
99
echo constant('MYSQLI_DATA_TRUNCATED')."\n";
1010
echo constant('MYSQLI_SERVER_QUERY_NO_GOOD_INDEX_USED')."\n";
1111
echo constant('MYSQLI_SERVER_QUERY_NO_INDEX_USED')."\n";
12-
echo constant('MYSQLI_SERVER_QUERY_WAS_SLOW')."\n";
13-
echo constant('MYSQLI_SERVER_PS_OUT_PARAMS')."\n";
12+
if (stristr(mysqli_get_client_info(), 'mysqlnd')) {
13+
echo constant('MYSQLI_SERVER_QUERY_WAS_SLOW')."\n";
14+
echo constant('MYSQLI_SERVER_PS_OUT_PARAMS')."\n";
15+
} else {
16+
print("\nDeprecated: Constant MYSQLI_SERVER_QUERY_WAS_SLOW is deprecated in dummy\n-1\n");
17+
print("\nDeprecated: Constant MYSQLI_SERVER_PS_OUT_PARAMS is deprecated in dummy\n-1\n");
18+
}
1419

1520
?>
1621
--EXPECTF--

ext/mysqli/tests/mysqli_fetch_column.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ mysqli
55
--SKIPIF--
66
<?php
77
require_once 'skipifconnectfailure.inc';
8+
if (!$IS_MYSQLND) {
9+
die("skip mysqlnd only test");
10+
}
811
?>
912
--FILE--
1013
<?php
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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"

ext/mysqli/tests/mysqli_options.phpt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ require_once 'skipifconnectfailure.inc';
1111
<?php
1212
require_once "connect.inc";
1313

14-
$valid_options = array(
15-
MYSQLI_READ_DEFAULT_GROUP => "MYSQLI_READ_DEFAULT_GROUP",
16-
MYSQLI_READ_DEFAULT_FILE => "MYSQLI_READ_DEFAULT_FILE",
17-
MYSQLI_OPT_CONNECT_TIMEOUT => "MYSQLI_OPT_CONNECT_TIMEOUT",
18-
MYSQLI_OPT_LOCAL_INFILE => "MYSQLI_OPT_LOCAL_INFILE",
19-
MYSQLI_INIT_COMMAND => "MYSQLI_INIT_COMMAND",
20-
MYSQLI_SET_CHARSET_NAME => "MYSQLI_SET_CHARSET_NAME",
21-
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT => "MYSQLI_OPT_SSL_VERIFY_SERVER_CERT",
22-
);
23-
24-
if ($IS_MYSQLND && defined('MYSQLI_OPT_NET_CMD_BUFFER_SIZE')) {
25-
$valid_options[] = constant('MYSQLI_OPT_NET_CMD_BUFFER_SIZE');
26-
}
27-
if ($IS_MYSQLND && defined('MYSQLI_OPT_NET_READ_BUFFER_SIZE')) {
28-
$valid_options[] = constant('MYSQLI_OPT_NET_READ_BUFFER_SIZE');
29-
}
30-
if ($IS_MYSQLND && defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
31-
$valid_options[] = constant('MYSQLI_OPT_INT_AND_FLOAT_NATIVE');
32-
}
33-
3414
$link = mysqli_init();
3515

3616
/* set it twice, checking if memory for the previous one is correctly freed */
@@ -76,7 +56,6 @@ mysqli_free_result($res);
7656
mysqli_close($link2);
7757

7858
foreach ($charsets as $charset) {
79-
$k = $charset['Charset'];
8059
/* The server currently 17.07.2007 can't handle data sent in ucs2 */
8160
/* The server currently 16.08.2010 can't handle data sent in utf16 and utf32 */
8261
if ($charset['Charset'] == 'ucs2' || $charset['Charset'] == 'utf16' || $charset['Charset'] == 'utf32') {
@@ -108,9 +87,12 @@ try {
10887
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
10988
$link = mysqli_init();
11089

111-
// test for error reporting
90+
// test for error reporting - only mysqlnd reports errors
11291
try {
11392
mysqli_options($link, MYSQLI_SET_CHARSET_NAME, "foobar");
93+
if (!$IS_MYSQLND) {
94+
print "Unknown character set\n";
95+
}
11496
} catch (mysqli_sql_exception $e) {
11597
echo $e->getMessage() . "\n";
11698
}

ext/mysqli/tests/mysqli_stmt_execute_bind_libmysql.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ $abc = 'abc';
2323
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
2424
$stmt->bind_param('sss', ...[&$abc, 42, $id]);
2525
$stmt->execute();
26-
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
26+
$stmt->bind_result($v1, $v2, $v3);
27+
$stmt->fetch();
28+
assert(['label'=>$v1, 'anon'=>$v2, 'num'=>$v3] === ['label'=>'a', 'anon'=>'abc', 'num'=>'42']);
2729
$stmt = null;
2830

2931
// 1. same as the control case, but skipping the middle-man (bind_param)

0 commit comments

Comments
 (0)