Skip to content

Commit 5fcf80b

Browse files
committed
Fix test case and add 12th check for too many params
1 parent ff70646 commit 5fcf80b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ext/mysqli/tests/mysqli_stmt_execute_bind.phpt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (mysqli_get_server_version($link) <= 40100) {
6666
try {
6767
$stmt->execute(42);
6868
} catch (TypeError $e) {
69-
echo '[004] '.$e->getMessage()."\n";
69+
echo '[004] '.$e->getMessage()."\n";
7070
}
7171
$stmt = null;
7272

@@ -100,7 +100,7 @@ if (mysqli_get_server_version($link) <= 40100) {
100100
$stmt->execute(); // no argument here. Values are already bound
101101
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
102102
try {
103-
$stmt->execute([]); // no params here. PDO doesn't throw an error, but mysqli does
103+
$stmt->execute([]); // no params here. PDO doesn't throw an error, but mysqli does
104104
} catch (mysqli_sql_exception $e) {
105105
echo '[006] '.$e->getMessage()."\n";
106106
}
@@ -109,16 +109,22 @@ if (mysqli_get_server_version($link) <= 40100) {
109109
// 10. mixing binding styles not possible. Also, NULL should stay NULL when bound as string
110110
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
111111
$stmt->bind_param('sss', ...['abc', 42, null]);
112-
$stmt->execute([null, null, $id]);
112+
$stmt->execute([null, null, $id]);
113113
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>null, 'num' => null]);
114114
$stmt = null;
115115

116116
// 11. array keys are ignored. Even numerical indices are not considered (PDO does a weird thing with the numerical indices)
117117
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
118-
$stmt->execute(['A'=>'abc', 2=>42, null=>$id]);
118+
$stmt->execute(['A'=>'abc', 2=>42, null=>$id]);
119119
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
120120
$stmt = null;
121121

122+
// 12. Too many parameters is not a problem. The redundant ones just get ignored
123+
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
124+
$stmt->execute(['abc', null, $id, 42]);
125+
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => null]);
126+
$stmt = null;
127+
122128

123129
mysqli_close($link);
124130
print "done!";
@@ -131,7 +137,7 @@ if (mysqli_get_server_version($link) <= 40100) {
131137
[001] No data supplied for 1 parameter in prepared statement
132138
[002] No data supplied for 3 parameters in prepared statement
133139
[003] No data supplied for parameters in prepared statement
134-
[004] mysqli_stmt::execute(): Argument #1 ($params) must be of type array, int given
135-
[005] mysqli_stmt::execute(): Argument #1 ($params) must be of type array, stdClass given
140+
[004] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, int given
141+
[005] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, stdClass given
136142
[006] No data supplied for 3 parameters in prepared statement
137143
done!

0 commit comments

Comments
 (0)