Skip to content

Commit 84a3be7

Browse files
committed
Make errors consisent with ValueError
1 parent 2611223 commit 84a3be7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,14 @@ PHP_FUNCTION(mysqli_stmt_execute)
826826
if(input_params) {
827827
zval *tmp;
828828
unsigned int index;
829+
unsigned int hash_num_elements;
830+
unsigned int param_count;
829831
MYSQLND_PARAM_BIND *params;
830832

831-
if(zend_hash_num_elements(Z_ARRVAL_P(input_params)) > mysql_stmt_param_count(stmt->stmt)) {
832-
zend_argument_count_error("The number of values must match the number of parameters in the prepared statement");
833+
hash_num_elements = zend_hash_num_elements(Z_ARRVAL_P(input_params));
834+
param_count = mysql_stmt_param_count(stmt->stmt);
835+
if(hash_num_elements != param_count) {
836+
zend_argument_value_error(ERROR_ARG_POS(2), "must consist of exactly %d elements, %d present", param_count, hash_num_elements);
833837
RETURN_THROWS();
834838
}
835839

ext/mysqli/tests/mysqli_stmt_execute_bind.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (mysqli_get_server_version($link) <= 40100) {
3838
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
3939
try {
4040
$stmt->execute([&$abc, 42]);
41-
} catch (mysqli_sql_exception $e) {
41+
} catch (ValueError $e) {
4242
echo '[001] '.$e->getMessage()."\n";
4343
}
4444
$stmt = null;
@@ -47,7 +47,7 @@ if (mysqli_get_server_version($link) <= 40100) {
4747
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
4848
try {
4949
$stmt->execute([&$abc, null, $id, 24]);
50-
} catch (ArgumentCountError $e) {
50+
} catch (ValueError $e) {
5151
echo '[002] '.$e->getMessage()."\n";
5252
}
5353
$stmt = null;
@@ -56,7 +56,7 @@ if (mysqli_get_server_version($link) <= 40100) {
5656
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
5757
try {
5858
$stmt->execute([]);
59-
} catch (mysqli_sql_exception $e) {
59+
} catch (ValueError $e) {
6060
echo '[003] '.$e->getMessage()."\n";
6161
}
6262
$stmt = null;
@@ -110,7 +110,7 @@ if (mysqli_get_server_version($link) <= 40100) {
110110
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
111111
try {
112112
$stmt->execute([]); // no params here. PDO doesn't throw an error, but mysqli does
113-
} catch (mysqli_sql_exception $e) {
113+
} catch (ValueError $e) {
114114
echo '[007] '.$e->getMessage()."\n";
115115
}
116116
$stmt = null;
@@ -137,11 +137,11 @@ if (mysqli_get_server_version($link) <= 40100) {
137137
require_once("clean_table.inc");
138138
?>
139139
--EXPECT--
140-
[001] No data supplied for 1 parameter in prepared statement
141-
[002] The number of values must match the number of parameters in the prepared statement
142-
[003] No data supplied for 3 parameters in prepared statement
140+
[001] mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 3 elements, 2 present
141+
[002] mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 3 elements, 4 present
142+
[003] mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 3 elements, 0 present
143143
[004] No data supplied for parameters in prepared statement
144144
[005] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, int given
145145
[006] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, stdClass given
146-
[007] No data supplied for 3 parameters in prepared statement
146+
[007] mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 3 elements, 0 present
147147
done!

0 commit comments

Comments
 (0)