Skip to content

Commit 231526b

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/pdo: Do not register a bindColumn() binding for an unknown column
2 parents 7dc859d + d07f376 commit 231526b

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ PHP NEWS
6767
- PDO:
6868
. Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
6969
column index. (Ilia Alshanetsky)
70+
. Fixed PDOStatement::bindColumn() registering a binding for a column name
71+
that is not in the result set. (Ilia Alshanetsky)
7072

7173
- PGSQL:
7274
. Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky)

‎ext/pdo/pdo_stmt.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
305305
spprintf(&tmp, 0, "Did not find column name '%s' in the defined columns; it will not be bound", ZSTR_VAL(param->name));
306306
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp);
307307
efree(tmp);
308+
return false;
308309
}
309310
}
310311

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
PDO: bindColumn() must fail for a column name that is not in the result set
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if (false == $dir) die('skip no driver');
9+
require_once $dir . 'pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16+
17+
$db = PDOTest::factory();
18+
$db->exec('CREATE TABLE pdo_bindcolumn_unknown_column (name varchar(255))');
19+
20+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
21+
$stmt = $db->query('SELECT name FROM pdo_bindcolumn_unknown_column');
22+
var_dump(@$stmt->bindColumn('nosuchcolumn', $var));
23+
24+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
25+
try {
26+
$stmt->bindColumn('nosuchcolumn', $var);
27+
} catch (PDOException $e) {
28+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
29+
}
30+
?>
31+
--CLEAN--
32+
<?php
33+
if (getenv('PDOTEST_DSN') === 'sqlite::memory:') return;
34+
35+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
36+
$db = PDOTest::factory();
37+
$db->exec('DROP TABLE pdo_bindcolumn_unknown_column');
38+
?>
39+
--EXPECT--
40+
bool(false)
41+
PDOException: SQLSTATE[HY000]: General error: Did not find column name 'nosuchcolumn' in the defined columns; it will not be bound

0 commit comments

Comments
 (0)