Hey, internals!
As many before me, I have come accross a need to load a SQLite extension.
While it is supported on the SQLite3 interface, popular frameworks (namely
Laravel) use solely PDO and loading extensions is not available on PDO.
I've looked into the history of this issue and it seems that
- Enabling SQLite extensions via SQL queries is disabled by default and
community agrees with this. - The suggested way to enable extensions is via the SQLite C API and that's
how SQLite3::loadExtension() does it. - The community does not want a new driver-specific
loadExtension
method
on the PDO class (there are some historical driver-specific methods).
Respecting these constraints, I would like to ask if the options
parameter
of PDO might be appropriate for this need? According to docs this parameter
is intended for driver-specific options:
https://www.php.net/manual/en/pdo.construct.php
Could it accept an extensions key with an array of extensions that the
SQLite PDO driver should load? This would not require changing the PDO
interface (apart from adding something like a PDO::SQLITE_LOAD_EXTENSIONS
constant for the key) and it would allow using the SQLite API for loading
the extension internally.
For me as a user of Laravel this would seem the easiest approach as passing
the options parameter to the PDO instance is already well supported while
replacing PDO with another class or calling methods on every new-booted PDO
instance is not that straightforward. I suspect the situation is similar on
other frameworks.
What do you think?
References:
- Bug report https://bugs.php.net/bug.php?id=64810
- Solution attempt creating PDO::sqliteCreateExtension()
https://github.com/php/php-src/pull/3368 - Solution attempt extending PDO into PDOSQLite class
https://github.com/php/php-src/pull/5765 - Discussion that new driver-specific methods are not welcome in PDO
https://externals.io/message/100268 - Similar discussion where the PDOSQLite class was proposed
https://externals.io/message/110578 - Discussion about eventually replacing SQLite3 with PDO/SQLite
https://externals.io/message/108256 (pointing this out as my proposal would
somewhat interfere - SQLite3 allows loading extensions at any time while the
PDO options are only used while initializing it) - A workaround https://github.com/Moxio/sqlite-extended-api
Thanks for your time,
Juris
Hi Juris,
Hey, internals!
As many before me, I have come accross a need to load a SQLite extension.
- The community does not want a new driver-specific
loadExtension
method
on the PDO class (there are some historical driver-specific methods).
I'm planning on submitting
https://wiki.php.net/rfc/pdo_driver_specific_subclasses in a few
weeks*, which will allow per-driver specific methods in a 'proper'
way.
cheers
Dan
Ack
Well in time for inclusion in PHP 8.3 at least.