Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDO and driver specific methods #5765

Draft
wants to merge 6 commits into
base: PHP-7.4
Choose a base branch
from

Conversation

pbowyer
Copy link

@pbowyer pbowyer commented Jun 24, 2020

This pull request is a spin-off from https://externals.io/message/110578.

What is it trying to achieve?

To provide full functionality there is a need to add driver-specific methods to PDO.

I discovered that I cannot load SQLite extensions such as GIS functions when using PDO-SQLite, and raised this on the mailing list. Rightly, no one wants to add driver-specific functionality to PDO - what's in PDO should be portable.

The consensus is that adding driver-specific subclassing of PDO is the way to go, and driver-specific functionality should be added here.

Why a Pull Request now?

I last wrote C 2 decades ago, and those were simple programs. I'm enjoying the challenge of digging into the PHP source code and doing copy&paste development but I don't know enough to complete this. I'm getting stuck and I need help.

I've been using SQLite as my testbed; if taken forward the work would need scaling to all drivers.

Preliminary plans

  • Add a PDOSQLite class
  • Make it extend PDO
  • Add a new PDO::connect() method
    • Make PDO::connect() do the same as new PDO() but return the right driver-instance (PDOSQLite in this case)
  • Expose a driver-specific method and constant
  • Confirm this approach is feasible and the PHP community approves of it

Far-Future plans

@Girgias
Copy link
Member

Girgias commented Jul 22, 2020

This should be based of the master branch and not PHP 7.4.

Doesn't seem like there is much to review currently as it's still a W.I.P. so you may want to mark this PR as a draft. :)

@pbowyer pbowyer marked this pull request as draft July 22, 2020 07:48
@pbowyer
Copy link
Author

pbowyer commented Jul 22, 2020

Thanks @Girgias, Draft was new to me!

@brzuchal
Copy link
Contributor

@pbowyer have you considered leaving PDO class as is but moving driver methods into driver specific classes implementing a PDODriver empty interface (maybe with some getName() at max) and then allowing to access these drivers from for eg. $pdo->driver or $pdo->getDriver() - this would allow the PDO class to stay simple and move extra methods out of it. For instance class PDOSQLite3Driver implements PDODriver {} would be a good example of it.

At least this is something which came to my mind today when trying to figure out if the pdo driver for sqlite should and where get added the mapping for sqlite3_backup_* functions family.

But if not then I can think of doing something like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants