forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix phpGH-16131: prevent subclass ctor/driver connection string mismatch
We now use the create driver-specific codepath without an object to change, so we go through the exceptions thrown there when there's any mismatches between the class being used and the connection string. The class entry fetch in the entry points was also wrong and did not get a valid class entry, this was also fixed. A test was added for this, although I'm not pleased by the fact it needs two real PDO drivers. A better way to test this would be nice, although it does match the original sample case.
- Loading branch information
1 parent
b32a941
commit 4e5fa34
Showing
2 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
GH-16131: Can use wrong driver in connection string with driver subclass | ||
--EXTENSIONS-- | ||
pdo | ||
pdo_mysql | ||
pdo_sqlite | ||
--FILE-- | ||
<?php | ||
|
||
// XXX: The fact we need two specific drivers makes this test annoying, | ||
// since we need two real drivers (or it gives a diff error for missing) | ||
// can it be done better? | ||
$db = new Pdo\Mysql('sqlite::memory:'); | ||
var_dump($db->getAttribute(PDO::ATTR_DRIVER_NAME)); | ||
--EXPECTF-- | ||
Fatal error: Uncaught PDOException: Pdo\%s::connect() cannot be called when connecting to the "%s" driver, either Pdo\%s::connect() or PDO::connect() must be called instead in %s:%d | ||
Stack trace: | ||
#0 %s(%d): PDO->__construct('%s') | ||
#1 {main} | ||
thrown in %s on line %d |