Skip to content

Commit 154f27a

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #79132
2 parents d5f6922 + ccb7f1c commit 154f27a

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

ext/pdo_mysql/mysql_driver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len
229229
S->num_params = mysql_stmt_param_count(S->stmt);
230230

231231
if (S->num_params) {
232-
S->params_given = 0;
233232
#ifdef PDO_USE_MYSQLND
234233
S->params = NULL;
235234
#else

ext/pdo_mysql/mysql_statement.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
387387
strcpy(stmt->error_code, "HY093");
388388
PDO_DBG_RETURN(0);
389389
}
390-
S->params_given++;
391390

392391
#ifndef PDO_USE_MYSQLND
393392
b = &S->params[param->paramno];
@@ -399,7 +398,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
399398
PDO_DBG_RETURN(1);
400399

401400
case PDO_PARAM_EVT_EXEC_PRE:
402-
if (S->params_given < (unsigned int) S->num_params) {
401+
if (zend_hash_num_elements(stmt->bound_params) < (unsigned int) S->num_params) {
403402
/* too few parameter bound */
404403
PDO_DBG_ERR("too few parameters bound");
405404
strcpy(stmt->error_code, "HY093");

ext/pdo_mysql/php_pdo_mysql_int.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ typedef struct {
141141
PDO_MYSQL_PARAM_BIND *bound_result;
142142
my_bool *out_null;
143143
zend_ulong *out_length;
144-
unsigned int params_given;
145144
unsigned max_length:1;
146145
/* Whether all result sets have been fully consumed.
147146
* If this flag is not set, they need to be consumed during destruction. */

ext/pdo_mysql/tests/bug79132.phpt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
Bug #79132: PDO re-uses parameter values from earlier calls to execute()
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
12+
13+
$pdo = MySQLPDOTest::factory();
14+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
16+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
17+
test($pdo);
18+
echo "\n";
19+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
20+
test($pdo);
21+
22+
function test($pdo) {
23+
$stmt = $pdo->prepare('select ? a, ? b');
24+
25+
$set = [
26+
['a', 'b'],
27+
['x'], /* second parameter is missing */
28+
[1 => 'y'], /* first parameter is missing */
29+
];
30+
31+
foreach ($set as $params) {
32+
try {
33+
var_dump($stmt->execute($params), $stmt->fetchAll(PDO::FETCH_ASSOC));
34+
} catch (PDOException $error) {
35+
echo $error->getMessage() . "\n";
36+
}
37+
}
38+
}
39+
40+
?>
41+
--EXPECT--
42+
bool(true)
43+
array(1) {
44+
[0]=>
45+
array(2) {
46+
["a"]=>
47+
string(1) "a"
48+
["b"]=>
49+
string(1) "b"
50+
}
51+
}
52+
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
53+
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
54+
55+
bool(true)
56+
array(1) {
57+
[0]=>
58+
array(2) {
59+
["a"]=>
60+
string(1) "a"
61+
["b"]=>
62+
string(1) "b"
63+
}
64+
}
65+
SQLSTATE[HY093]: Invalid parameter number
66+
SQLSTATE[HY093]: Invalid parameter number

0 commit comments

Comments
 (0)