WordPress Data base Plugin

Mar 13, 2012   //   by phpfreelancer.biz   //   Blog, Wordpress Plugin Tutorial  //  No Comments

On wordpress front-end I have a custom made form. I want to store the form entries in a database table on wordpress back-end. Is there any way(plugin) to do this?

In order to insert data into a database table, it is a best practice to use $wpdb.

It’s exactly the same as a normal MySQL query using PHP only you’re using the wpdb class for some PHP variables. Just output your query string which uses wpdb. If it looks like a normal MySQL query that would work, then it will work with the wpdb.Methods in the wpdb class should not be called directly. WordPress provides a global variable $wpdb, which is an instantiation of the class already set up to talk to the WordPress database. Always use the global $wpdb variable.

Run Any Query on the Database:

The query function allows you to execute any SQL query on the WordPress database. It is best to use a more specific function (see below), however, for SELECT queries.

<?php $wpdb->query('query'); ?>

query (string)- The SQL query you wish to execute.


Delete the ‘gargle’ meta key and value from Post 13.

	DELETE FROM $wpdb->postmeta 
	WHERE post_id = '13'
	AND meta_key = 'gargle'

Leave a comment

Share This Post

RSS Wordpress News