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 @@ -41,6 +41,8 @@ PHP NEWS
- PDO:
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
persistent connection. (Ilia Alshanetsky)
. Fixed constructor option errors naming argument #3 ($password) instead
of argument #4 ($options). (Ilia Alshanetsky)

- Phpdbg:
. Fix wrong command names. (ndossche, Weilin Du)
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ PDO_API void php_pdo_internal_construct_driver(INTERNAL_FUNCTION_PARAMETERS, zen
ZVAL_DEREF(attr_value);

/* TODO: Should the constructor fail when the attribute cannot be set? */
pdo_dbh_attribute_set(dbh, long_key, attr_value, 3);
pdo_dbh_attribute_set(dbh, long_key, attr_value, 4);
} ZEND_HASH_FOREACH_END();
}

Expand Down
38 changes: 38 additions & 0 deletions ext/pdo/tests/pdo_constructor_option_argnum.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
PDO Common: Constructor option errors report $options as argument #4
--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';

foreach ([false, true] as $useConnectMethod) {
foreach ([[PDO::ATTR_ERRMODE => 999], [PDO::ATTR_STATEMENT_CLASS => 'PDOStatement']] as $options) {
putenv("PDOTEST_ATTR=" . serialize($options));
try {
PDOTest::factory(PDO::class, $useConnectMethod);
} catch (Error $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
}

putenv("PDOTEST_ATTR=" . serialize([PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_NUM]));
$db = PDOTest::factory(PDO::class, $useConnectMethod);
var_dump($db->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE) === PDO::FETCH_NUM);
}
?>
--EXPECT--
ValueError: PDO::__construct(): Argument #4 ($options) Error mode must be one of the PDO::ERRMODE_* constants
TypeError: PDO::__construct(): Argument #4 ($options) PDO::ATTR_STATEMENT_CLASS value must be of type array, string given
bool(true)
ValueError: PDO::connect(): Argument #4 ($options) Error mode must be one of the PDO::ERRMODE_* constants
TypeError: PDO::connect(): Argument #4 ($options) PDO::ATTR_STATEMENT_CLASS value must be of type array, string given
bool(true)
Loading