> On 24 Jun 2022, at 22:45, Dan Ackroyd <dan...@basereality.com> wrote:
> 
> 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 <ram...@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.
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
> 

Hi Dan,

Re: the usefulness of separate classes per driver:

One thing of note is for query builders that abstract concepts for the end 
user. It’s often necessary to know what the underlying DB type is when 
generating a query. Perfect example is MySQL’s non standard field quoting 
character for example.

It’s possible already using `PDO::getAttribute` call but if you’re going to 
know from the class type for SQLite it’d be useful to know for others too. 

It’s not the end of the world to not have that convenience but there’s 
definitely use for it.

Cheers

Stephen 

Reply via email to