Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does wordpress code base use mysqli or PDO?

I know PDO is superior to mysqli but mysqli is not bad neither. Plus from one of the features of what makes PDO is superior to mysqli ( that is being database agnostic ) does not mean much to WordPress as WordPress will always use mysql server. But binding params with data types is something PDO supports but mysqli does not and it's a good thing.

My guts tell me that WordPress does use mysqli but I could not see it in the code base yet.

My second question is if WordPress is using mysqli, is it because of speed concerns or is it because back in the earlier days (when WP was being developed), PDO wasn't just there yet?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

WordPress uses mysql_* functions.

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/wp-db.php

It has used those ever since I can remember, which probably answers your last question. It is what I would consider legacy code. I suspect it will be updated sometime soon (those functions were only deprecated as of PHP 5.5, I believe). I don't know which route development will go.

Link to a ticket in Trac, courtesy of Wyck (from a comment below):

http://core.trac.wordpress.org/ticket/21663

share|improve this answer
    
I checked the code at wp-db.php. On line, 1133, it's got the db_connect function and according to it, it's not even mysqli. I'm confused. line 1143 clearly has this; $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); and according to the PHP manual, ( php.net/manual/en/function.mysql-connect.php ), this is a mysql code, Not mysqli. Does WP really use mysql ? –  Average Joe Feb 6 '13 at 0:25
5  
Wordpress uses outdated functions, since mysql_connect has officially been depreciated, wp will be moving hopefully to PDO soon (soon is 1-2 years). Ref: core.trac.wordpress.org/ticket/21663 –  Wyck Feb 6 '13 at 0:44
    
@AverageJoe ... yes, like I said, WordPress uses mysql functions. Like Wyck, I am hoping for PDO, but I don't know which way it will go. –  s_ha_dum Feb 6 '13 at 1:01
    
Thank you for the trac link Wyck. s_ha_dum please include this link ( core.trac.wordpress.org/ticket/21663 ) in your answer and correct the grammar where you go "If has used those ever since I can remember," when you get a chance. Thank you –  Average Joe Feb 6 '13 at 1:52
    
A little bump. This was written one light year ago.. But today I believe we have mysqli_* in wordpress since some versions, right? –  Carl Lindberg Apr 7 at 12:29

An update for Wordpress 3.9+ - with PHP 5.5 deprecating the mysql_* functions Wordpress has begun using the mysqli if it is available on the server. Your future plugins and code should take this into consideration and stop using mysql_*. Right now, in 3.9, wordpress checks for the availability of mysqli and uses it if available. If not it uses mysql_* but that check will be removed at the earliest possible convenience. Down the road it seems they will be using PDO but that is a larger project.

Here is an FAQ and announcement on it:

http://make.wordpress.org/core/2014/04/07/mysql-in-wordpress-3-9/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.