WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on backup-related plugin and from some research of existing plugins - they seem to favor using PHP's mysql_* functions, rather than $wpdb.

Is $wpdb overhead considerable enough that it is unsuitable for such task as querying whole database tables?

share|improve this question
up vote 5 down vote accepted

There is a significant amount of memory usage if you use the $wpdb for queries that return very large result sets. $wpdb loads the entire results from any given query into memory. So if you're, say, selecting all the posts, then it'll try to load the whole thing into memory immediately.

So for something like a backup plugin, direct calls to mySQL with loops for retrieving the data make more sense.

share|improve this answer
Anything from $wpdb that I still could/should use, such as it already opened db connection? If it's too much I can ask separate question on that. – Rarst Jul 5 '11 at 18:13
Dump the variables in the object and take a look for yourself. All the useful stuff is stored there. The handle is in $wpdb->dbh, the various tables and prefixes for them are defined, the database is already selected, etc. It's just the query() and similar functions that will cause the overhead for large result sets. – Otto Jul 5 '11 at 18:16

Just in case someone reads the Q: Here you got a pastebin from the global $wpdb object and here you got a little memory useage tracing function. Any comment on the function is appreciated as it's not tested so far.

share|improve this answer

Your Answer


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.