Skip to content

What $wpdb Is, and Why I Try Not To Use It

More than half of what matters about a WordPress site is stored in its (typically MySQL) database. Why? Because WordPress stores all its “content” in the database. For most people, that makes it even more important (and harder to replace) than their plugins and themes, and possibly even media files.

In the simplest terms possible $wpdb is how the database is accessed 99% of the time on a WordPress site. It’s WordPress’s database interacting agent.

In the simplest terms possible $wpdb is how the database is accessed 99% of the time on a WordPress site. It’s WordPress’s database interacting object. And it’s quite good, rather useful, and more than a bit interesting. It’s also not nearly as necessary to understand as a new developer might expect. I rarely use it outside of a small number of cases where it’s worthwhile to make and maintain my own database tables in a plugin. For most of my data creation and fetching needs, WordPress offers other functions which are a great deal easier.

So our goal is to get into a bit more detail about $wpdb is and some of its capabilities, and then we’ll answer the more important issue: when you should and shouldn’t use it.

Understanding the Basics of Database Interactions in PHP

SQL stands for “structured query language” and its the general syntax that people use to put data into and retrieve data from relational databases like MySQL.

Yay! 🎉 You made it to the end of the article!
David Hayes
Share:

2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
WordCracker
April 6, 2016 10:37 pm

Nice post. Thanks for sharing this.

Tweet Parade (no.49-2015) - Best Articles of Last Week | gonzoblog
December 6, 2015 9:03 am

[…] What $wpdb Is, and Why I Try Not To Use It – So our goal is to get into a bit more detail about $wpdb is and some of its capabilities, and then we’ll answer the more important issue: when you should and shouldn’t use it. […]

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!