@@ -66,7 +66,7 @@ if (mysqli_get_server_version($link) <= 40100) {
66
66
try {
67
67
$ stmt ->execute (42 );
68
68
} catch (TypeError $ e ) {
69
- echo '[004] ' .$ e ->getMessage ()."\n" ;
69
+ echo '[004] ' .$ e ->getMessage ()."\n" ;
70
70
}
71
71
$ stmt = null ;
72
72
@@ -100,7 +100,7 @@ if (mysqli_get_server_version($link) <= 40100) {
100
100
$ stmt ->execute (); // no argument here. Values are already bound
101
101
assert ($ stmt ->get_result ()->fetch_assoc () === ['label ' =>'a ' , 'anon ' =>'abc ' , 'num ' => '42 ' ]);
102
102
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
104
104
} catch (mysqli_sql_exception $ e ) {
105
105
echo '[006] ' .$ e ->getMessage ()."\n" ;
106
106
}
@@ -109,16 +109,22 @@ if (mysqli_get_server_version($link) <= 40100) {
109
109
// 10. mixing binding styles not possible. Also, NULL should stay NULL when bound as string
110
110
$ stmt = $ link ->prepare ('SELECT label, ? AS anon, ? AS num FROM test WHERE id=? ' );
111
111
$ stmt ->bind_param ('sss ' , ...['abc ' , 42 , null ]);
112
- $ stmt ->execute ([null , null , $ id ]);
112
+ $ stmt ->execute ([null , null , $ id ]);
113
113
assert ($ stmt ->get_result ()->fetch_assoc () === ['label ' =>'a ' , 'anon ' =>null , 'num ' => null ]);
114
114
$ stmt = null ;
115
115
116
116
// 11. array keys are ignored. Even numerical indices are not considered (PDO does a weird thing with the numerical indices)
117
117
$ 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 ]);
119
119
assert ($ stmt ->get_result ()->fetch_assoc () === ['label ' =>'a ' , 'anon ' =>'abc ' , 'num ' => '42 ' ]);
120
120
$ stmt = null ;
121
121
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
+
122
128
123
129
mysqli_close ($ link );
124
130
print "done! " ;
@@ -131,7 +137,7 @@ if (mysqli_get_server_version($link) <= 40100) {
131
137
[001] No data supplied for 1 parameter in prepared statement
132
138
[002] No data supplied for 3 parameters in prepared statement
133
139
[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
136
142
[006] No data supplied for 3 parameters in prepared statement
137
143
done!
0 commit comments