Skip to content

Mysqli support#6

Merged
JJJ merged 9 commits into
masterfrom
unknown repository
May 2, 2016
Merged

Mysqli support#6
JJJ merged 9 commits into
masterfrom
unknown repository

Conversation

@spacedmonkey
Copy link
Copy Markdown
Collaborator

Surprising hyperdb doesn't support mysqli. There are forks out that do mysqli by @soulseekah . But this fork doesn't support falling back if mysqli is not present.

This pull request tries to map as close to WP core naming, with the following methods being synced from core.

  • check_connection
  • select
  • set_sql_mode
  • _do_query

Currently testing this in our testing environment. Results looking good.

Fixes #4

spacedmonkey added 7 commits March 14, 2016 19:34
Much of this is copied from the standard wpdb class. These is a lot of
overriding, so that multiple databases can be supported.
Also added support for the reconnect_retries variable added in wp 3.9.
Support for connecting to db with mysqli. Also supports persistent
connections. If connection fails, tries again with mysql. If connection
fails, try again with mysql_connect functions.
The core version of this method would not have worked as it didn’t pass
the dbh param. This is a hacked version from WP 4.5
Assign the resource connection to dbhs.
With mysqli in the mix, do correct type checking.
Check if is db object. If not, return.
@spacedmonkey
Copy link
Copy Markdown
Collaborator Author

We have this running in production now and it working great. It should be merged. @johnjamesjacoby

@JJJ
Copy link
Copy Markdown
Collaborator

JJJ commented Mar 30, 2016

This looks great; thank you for doing this all, and submitting upstream here!

After looking at the work you've put in, I have 1 question: should we continue down the road of including these both in the same drop-in, or does it make more sense to have 2 separate files (1 for MySQL and another for MySQLi)?

Obviously, some of the improvements you've made do also improve MySQL support, so dividing this back up would not be a very fun task. If we think a few years ahead, is it possible we'd need to keep dividing this up to support more flavors, and be setting ourselves up for ever-increasing complexity?

@spacedmonkey
Copy link
Copy Markdown
Collaborator Author

So there is already a fork of hyperdb that supports mysqli. It could be found here - https://github.com/soulseekah/hyperdb-mysqli

So the reason I added supported for mysqli into this and not another file was for the following reason. Imagine you have multiple pools of servers, dev, stage and production. Your dev box is php 5.6 with mysqli support but production is 5.4. With support for both you use the same plugin for multiple environments. Detecting mysqli support means that you as a dev, don't need to understand the difference, it just "works". This is how the core works with mysqli.

As for supporting other database drivers like pdo, there is this for pdo. As pdo is an optional database driver for now, I am sure the use case is small. I think it is a problem we should think about later.

Currently I think the wpdb class should do a better job of abstracting the code that implement the database drivers. If you could have method like query, ping, error etc. Then all a pdo drivers should do is override these methods. I am just dreaming now. I have a card up related to this - https://core.trac.wordpress.org/ticket/36242 I do need to add more detail onto it....

@JJJ
Copy link
Copy Markdown
Collaborator

JJJ commented Mar 30, 2016

Imagine you have multiple pools of servers, dev, stage and production. Your dev box is php 5.6 with mysqli support but production is 5.4. With support for both you use the same plugin for multiple environments.

That's compelling, and makes sense. Thanks for reminding me that that is a scenario someone may find themselves in.

@rmccue
Copy link
Copy Markdown

rmccue commented Apr 7, 2016

We're starting to run this on our servers, as we need mysqli for PHP 7+ :)

I think having the switch for mysql/mysqli makes sense at the moment, but should probably be revisited in the future, as mysql is considered deprecated. In the meantime, 👍 on merging.

@joehoyle
Copy link
Copy Markdown

joehoyle commented Apr 29, 2016

Just echoing what @rmccue said, we are using this is production for some sites in the 20 million page views a month range, and haven't run into any issues yet.

@JJJ JJJ merged commit 2ac73c1 into stuttter:master May 2, 2016
@spacedmonkey
Copy link
Copy Markdown
Collaborator Author

I have been running a similar level of traffic haven't seen any issues related to this. I get out of memory errors sometimes, but I think this related to issues in the core and a memory leak on longer running processes.

I did find one small php warning on some edge cases. I have a PR for it #8 . Otherwise, thanks for the merge.

spacedmonkey pushed a commit that referenced this pull request Jul 12, 2016
spacedmonkey pushed a commit that referenced this pull request Jul 12, 2016
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.

With RO db, prevent reading from slaves after write will cause failed SELECT with the same table after writes mysqli support for PHP7

4 participants