Re: Re: [RFC] [Under Discussion] PDO driver specific sub-classes
| From: | Dan Ackroyd | Date: | Fri, 24 Jun 2022 15:38:02 +0000 |
| Subject: | Re: Re: [RFC] [Under Discussion] PDO driver specific sub-classes | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118088@lists.php.net to get a copy of this message | ||
Larry Garfield wrote:
> "Create all DB sub-classes?" - I'd say they all should have subclasses, even
> if empty. It's more consistent* that way, and you can then also rely on
> instanceof giving you useful information rather than "well, it's not one of
> the special ones, so beyond that, NFI."
You can get the database type through $db->getAttribute(PDO::ATTR_DRIVER_NAME);
On Tue, 21 Jun 2022 at 15:39, Ben Ramsey <ramsey@php.net> wrote:
>
> Is there a reason we shouldn't go ahead and add subclasses for all
database connection types,
YAGNI, and I'm lazy. But mostly, I don't think adding them now
actually helps achieve anything.
Being able to check if the class has specialised methods is useful:
if ($pdo instanceof PDOSqlite) {
$pdo->loadExtension(...);
// do fun stuff with extension here.
}
But for the classes that have no specialised method:
if ($pdo instanceof PDOMysql) {
// What would be of utility here?
}
cheers
Dan
Ack
* How to value being consistent is an aesthetic choice that many other
programmers disagree with me on; "The fundamental guiding force to
bear in mind is whether something is useful or not. Consistency might
satisfy a personal desire for order and simplicity, but most of the
time just having things be consistent is a lower priority than making
choices that are useful." or in this case, less code to write and
maintain.