Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ PHP NEWS
- PDO:
. Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
column index. (Ilia Alshanetsky)
. Fixed PDOStatement::bindColumn() registering a binding for a column name
that is not in the result set. (Ilia Alshanetsky)

- Readline:
. Fixed a heap over-read in the interactive shell prompt when cli.prompt is
Expand Down
1 change: 1 addition & 0 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
spprintf(&tmp, 0, "Did not find column name '%s' in the defined columns; it will not be bound", ZSTR_VAL(param->name));
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp);
efree(tmp);
return 0;
}
}

Expand Down
41 changes: 41 additions & 0 deletions ext/pdo/tests/pdo_bindcolumn_unknown_column.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
PDO: bindColumn() must fail for a column name that is not in the result set
--EXTENSIONS--
pdo
--SKIPIF--
<?php
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';

$db = PDOTest::factory();
$db->exec('CREATE TABLE pdo_bindcolumn_unknown_column (name varchar(255))');

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$stmt = $db->query('SELECT name FROM pdo_bindcolumn_unknown_column');
var_dump(@$stmt->bindColumn('nosuchcolumn', $var));

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt->bindColumn('nosuchcolumn', $var);
} catch (PDOException $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
}
?>
--CLEAN--
<?php
if (getenv('PDOTEST_DSN') === 'sqlite::memory:') return;

require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec('DROP TABLE pdo_bindcolumn_unknown_column');
?>
--EXPECT--
bool(false)
PDOException: SQLSTATE[HY000]: General error: Did not find column name 'nosuchcolumn' in the defined columns; it will not be bound
Loading