In WordPress 3.9, we added an extra layer to WPDB, causing it to switch to using the mysqli PHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher library, when using PHP 5.5 or higher.
For plugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party developers, this means that you absolutely shouldn’t be using PHP’s mysql_*() functions any more – you can use the equivalent WPDB functions instead.
There are a few different options for replacing the query functions, depending on what you want to do:
As a drop in replacement to run a query that you don’t expect a return value from (i.e., an INSERT, UPDATE or DELETE query), use $wpdb->query(). This will always return the number of rows effected by the query.
Alternatively, $wpdb->insert(), $wpdb->update(), $wpdb->delete() and $wpdb->replace() are all helper functions that will automatically escape your data, then generate and run the queries for you. Ideally, you should never need to write an SQL statement!
If you have a SELECT query, for which you’d normally do a mysql_query() followed by a mysql_fetch_*(), WPDB lets you combine this into one function call.
To get all of the results from a query that returns more than one row, use $wpdb->get_results() to return an array of objects containing your data.
There are also some shortcut functions for common usage:
If you only need a single row from your query, $wpdb->get_row() will return just the data object from that row.
If you only need a single column from a single row, $wpdb->get_var() will return only that field.
And if you need a single column, $wpdb->get_col() will return an array of all the data from that column.
For a drop in replacement, you can use esc_sql(). That said, we strongly recommend switching to $wpdb->prepare(), instead. We have a pretty thorough tutorial available for $wpdb->prepare().
If you need to get the Insert ID from the last query, $wpdb->insert_id is where you need to look.
Updating your plugin to use WPDB will also future proof it for if we make changes to how WordPress connects to the database – we’ll always maintain backwards compatibility with the current WPDB interface.
For more reading, check the WPDB Codex page, and #21663.
If you’re using MySQL MySQL is a relational database management system. A database is a structured collection of data where content, configuration and other options are stored. https://www.mysql.com/. in a way that I haven’t covered here, please post it in the comments, we’d be happy to help you out!