[drupal-devel] [feature] MySQLi support

m3avrck drupal-devel at drupal.org
Tue Sep 6 18:27:46 UTC 2005

Issue status update for 
Post a follow up: 

 Project:      Drupal
 Version:      cvs
 Component:    database system
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  nsk
 Updated by:   m3avrck
 Status:       patch (ready to be committed)

very true. i guess this patch then is indeed a good "first" step to get
the initial, working functionality into core. then after that though,
we do need to revisit the issue and update code to make better use of
mysqli_stmt(), which will not only provide better performance, but much
*better* security, and we could probably start to get rid of redudant
code elsewhere in the code for such checks.


Previous comments:

Mon, 29 Aug 2005 06:59:53 +0000 : nsk

Attachment: http://drupal.org/files/issues/nskpatch.tar.bz2 (4.14 KB)

I added MySQLi support to Drupal by adding a database.mysqli.inc file.
After chx's suggestion I also removed $row from db_result from both
mysqli and mysql files.

Users are supposed to connect to Drupal with a mysqli "URL" in their
settings.php. Just adding an "i" in the mysql entry in settings.php
would work.

MySQLi is the new MySQL client in PHP which connects to MySQL 4.1, 5.0
and beyond. MySQLi replaces the older MySQL library which was popular
with MySQL 3.23 and 4.0.


The older MySQL client does not support full functionality with MySQL
4.1, that's why MySQLi is important.

MySQLi works in PHP 4.1.3 or above, and is more popular in PHP 5.

MySQLi means MySQL Improved.

This patch should be included in core.


Mon, 29 Aug 2005 07:08:07 +0000 : nsk

Attachment: http://drupal.org/files/issues/nskpatch1.diff (7.1 KB)

Here is the diff for mysqli against Drupal CVS HEAD.


Mon, 29 Aug 2005 07:08:56 +0000 : nsk

Attachment: http://drupal.org/files/issues/nskpatch2.diff (645 bytes)

Here is the diff for mysql against DRUPAL CVS HEAD. The change was
proposed by chx on IRC.


Mon, 29 Aug 2005 07:13:28 +0000 : nsk

With this message hereby I release all my changes to the files in this
patch (database.mysqli.inc and database.mysql.inc) in GPL 2 (and later
versions), as well as releasing them into the public domain. The
changes I made are show in the diffs. An external URL where users can
find some documentation is:


Mon, 29 Aug 2005 13:22:42 +0000 : Thomas Ilsche

big +1, however not tested yet (will do later today)


Mon, 29 Aug 2005 16:03:33 +0000 : Thox

See duplicate issue: #24264 [1].
[1] http://drupal.org/node/24264


Mon, 29 Aug 2005 16:16:17 +0000 : m3avrck

Using that file, I get this error right away:

Parse error: syntax error, unexpected ',' in C:\Documents and
Documents\websites\drupal_cvs\drupal\includes\database.mysqli.inc on
line 34

Doing some digging through the documentation, it looks like the
mysqli_real_connect() [2] is being used *improplerly*.

This function call works with no problems:
  @mysqli_real_connect($connection, $url['host'], $url['user'],
$url['pass'], (substr($url['path'], 1)), $url['port'], null,

If this is indeed the correct call (it appears to be but can't really
test whether the ports, sockets part is working), then the code circa
line 27 that checks for the port can be deleted since the function call
handles this.

Additionally, the database check on line 51 needs to be moved up since
the database is selected during the mysqli_real_connect() now.

Overall, code needs some work and cleanup.

Peformance wise, noticed a 10ms decrease in page generation times for a
few pages (not thorougly tested performance wise however, just a quick
and dirty observation).
[2] http://us2.php.net/manual/en/function.mysqli-real-connect.php


Mon, 29 Aug 2005 16:17:34 +0000 : m3avrck

Forgot to mention tested this with PHP5.0.3 and MySQL 4.1.11 on Windows
2003 SP1.


Mon, 29 Aug 2005 16:20:36 +0000 : m3avrck

Thox, the reported duplicate issue is using an out of date
database.mysql.inc file. I believe Drumm added quite a bit of code for
friendlier errors. Seems those two files need to be merged for proper
MySQLi support. I'll see what I can do later today if I have some time.


Mon, 29 Aug 2005 16:56:24 +0000 : m3avrck

Attachment: http://drupal.org/files/issues/database.mysqli_2.inc (8.51 KB)

Ok I've taken the latest HEAD version of database.mysql.inc, merged this
with NSK's recommendations, and then merged that with Thox's
database.mysqli.inc (see link a few comments up) whose database code
was based on out of an out of date version of the include file.

Also went through and tweaked and it looks like this patch is ready to
go. Just tested it here and it is running *now* on average, 40ms
*faster* than the regular mysql library.

Patch needs some more testing but I believe it is ready to go.
Optionally, lines 27 can be removed and the mysqli_real_connect() can
be updated with the $url['port']. No way to confirm if this will work
100% but we can get rid of some extraneous code if someone can confirm.

See attached file.


Mon, 29 Aug 2005 17:01:57 +0000 : m3avrck

Updated status of feature request.


Mon, 29 Aug 2005 20:38:18 +0000 : Thomas Ilsche

Attachment: http://drupal.org/files/issues/database.mysql.inc.file (8.83 KB)

Tested the file -> however des not work with HEAD due to [1].
However with a slight change it works well.
I have attached the changed one (renamed so the content is not

[1] http://drupal.org/node/22911


Mon, 29 Aug 2005 20:45:53 +0000 : m3avrck

Thomas this looks like the regular mysql file... nothing changed in
this. Attached wrong file I am thinking?


Mon, 29 Aug 2005 20:57:03 +0000 : Thomas Ilsche

Attachment: http://drupal.org/files/issues/database.mysqli.inc.file (8.71 KB)

your right. sorry, wrong file.


Mon, 29 Aug 2005 21:14:17 +0000 : m3avrck

Great catch, working perfect now with latest HEAD. Any more testers, I
think this code is just about ready to submitted to core.


Tue, 30 Aug 2005 00:22:49 +0000 : kbahey

>From the performance point of view, MySQLi can be slower or faster than
regular MySQL, depending on how ti is used.

According to this benchmark [3], using mysqli_stmt() has a performance
edge over mysql_query(), which is in turn faster than mysqli_query().

NSK or Thomas can take a look and decide if it is worth so to do it.
[3] http://www.johnjawed.com/benchmarks/


Sat, 03 Sep 2005 19:14:42 +0000 : nsk

Yes I agree mysqli_stmt()  is faster, if I have time I'll implement this


Mon, 05 Sep 2005 15:56:59 +0000 : moshe weitzman

tested - works for me.


Mon, 05 Sep 2005 15:58:04 +0000 : moshe weitzman

oops. set to proper status


Mon, 05 Sep 2005 15:59:48 +0000 : m3avrck

Although I do agree this code is working, we should in fact rewrite it
to make user of the more advanced MySQLi techniques, notably
mysqli_stmt() for *true* performance gains. Otherwise this patch
doesn't really offer any incentives.


Mon, 05 Sep 2005 16:18:04 +0000 : moshe weitzman

one step at a time, folks. prepared statements is a much more complex
undertaking. there are benefits without using that feature. i quote
from http://www.zend.com/php5/articles/php5-mysqli.php:

 Beyond gaining access to the new features of MySQL 4.1+, why would
anyone want to switch to using ext/mysqli?

In addition to the functionality mentioned above, ext/mysqli also has
some other serious benefits:

    * Greater speed. Enhancements in both the extension and in MySQL
have made most operations faster, with certain operations becoming up
to 40 times faster as compared to ext/mysql.
    * Better security. In older versions of the MySQL RDBMS, the
possibility existed for an attacker to extract weak password hashes
from the network and then recreate a user's password. The new
authentication procedure is much more robust and mirrors the
attack-resistant authentication procedure of tools like SSH.

More information about the drupal-devel mailing list