Skip to content

Commit e2ccd45

Browse files
committed
Add error for libmysqlclient
A new test case was added to check for the exception with libmysqlclient
1 parent 4611916 commit e2ccd45

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,8 @@ PHP_FUNCTION(mysqli_stmt_execute)
822822
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
823823

824824
// bind-in-execute
825-
#if defined(MYSQLI_USE_MYSQLND)
826825
if (input_params) {
826+
#if defined(MYSQLI_USE_MYSQLND)
827827
zval *tmp;
828828
unsigned int index;
829829
unsigned int hash_num_elements;
@@ -854,8 +854,11 @@ PHP_FUNCTION(mysqli_stmt_execute)
854854
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
855855
RETVAL_FALSE;
856856
}
857-
}
857+
#else
858+
zend_argument_count_error("Binding parameters in execute is not supported with libmysqlclient");
859+
RETURN_THROWS();
858860
#endif
861+
}
859862

860863
#ifndef MYSQLI_USE_MYSQLND
861864
if (stmt->param.var_cnt) {

ext/mysqli/tests/mysqli_stmt_execute_bind.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
1010
if (mysqli_get_server_version($link) <= 40100) {
1111
die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link)));
1212
}
13+
if (!stristr(mysqli_get_client_info(), 'mysqlnd')) {
14+
die("skip: only available in mysqlnd");
15+
}
1316
?>
1417
--FILE--
1518
<?php
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
mysqli_stmt_execute() - bind in execute
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
8+
die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
9+
}
10+
if (mysqli_get_server_version($link) <= 40100) {
11+
die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link)));
12+
}
13+
if (stristr(mysqli_get_client_info(), 'mysqlnd')) {
14+
die("skip: only applicable for libmysqlclient");
15+
}
16+
?>
17+
--FILE--
18+
<?php
19+
require_once("connect.inc");
20+
21+
require('table.inc');
22+
23+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
24+
25+
// first, control case
26+
$id = 1;
27+
$abc = 'abc';
28+
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
29+
$stmt->bind_param('sss', ...[&$abc, 42, $id]);
30+
$stmt->execute();
31+
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
32+
$stmt = null;
33+
34+
// 1. same as the control case, but skipping the middle-man (bind_param)
35+
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
36+
try {
37+
$stmt->execute([&$abc, 42, $id]);
38+
} catch (ArgumentCountError $e) {
39+
echo '[001] '.$e->getMessage()."\n";
40+
}
41+
$stmt = null;
42+
43+
mysqli_close($link);
44+
print "done!";
45+
?>
46+
--CLEAN--
47+
<?php
48+
require_once("clean_table.inc");
49+
?>
50+
--EXPECT--
51+
[001] Binding parameters in execute is not supported with libmysqlclient
52+
done!

0 commit comments

Comments
 (0)