Skip to content
Open
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
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ PHP 8.6 UPGRADE NOTES
execution error occurs (e.g. malformed UTF-8 input with the /u modifier).
This is consistent with other preg_* functions.

- PDO:
. PDOStatement::bindColumn() now throws a ValueError when the column name is
not present in the result set. It previously reported the condition
through PDO::ATTR_ERRMODE and returned false.

- PGSQL:
. pg_fetch_object() now reports the ValueError for a non-empty
$constructor_args on a class without a constructor on the
Expand Down
7 changes: 1 addition & 6 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,7 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
/* if you prepare and then execute passing an array of params keyed by names,
* then this will trigger, and we don't want that */
if (param->paramno == -1) {
/* Should this always be an Error? */
char *tmp;
/* TODO Error? */
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);
zend_argument_value_error(1, "must refer to a column present in the result set, \"%s\" given", ZSTR_VAL(param->name));
return false;
}
}
Expand Down
30 changes: 18 additions & 12 deletions ext/pdo/tests/pdo_bindcolumn_unknown_column.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
PDO: bindColumn() must fail for a column name that is not in the result set
PDO: bindColumn() must throw for a column name that is not in the result set
--EXTENSIONS--
pdo
--SKIPIF--
Expand All @@ -17,16 +17,20 @@ 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;
// The error mode must not affect a ValueError.
foreach ([PDO::ERRMODE_SILENT, PDO::ERRMODE_WARNING, PDO::ERRMODE_EXCEPTION] as $mode) {
$db->setAttribute(PDO::ATTR_ERRMODE, $mode);
$stmt = $db->query('SELECT name FROM pdo_bindcolumn_unknown_column');
try {
$stmt->bindColumn('nosuchcolumn', $var);
} catch (ValueError $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
}

// A column that does exist still binds.
$stmt = $db->query('SELECT name FROM pdo_bindcolumn_unknown_column');
var_dump($stmt->bindColumn('name', $var));
?>
--CLEAN--
<?php
Expand All @@ -37,5 +41,7 @@ $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
ValueError: PDOStatement::bindColumn(): Argument #1 ($column) must refer to a column present in the result set, "nosuchcolumn" given
ValueError: PDOStatement::bindColumn(): Argument #1 ($column) must refer to a column present in the result set, "nosuchcolumn" given
ValueError: PDOStatement::bindColumn(): Argument #1 ($column) must refer to a column present in the result set, "nosuchcolumn" given
bool(true)
Loading