Insert update and delete in WordPress.

By -

In the core php, we need to write at-least 10 to 15 lines, sometimes more than that for the database connection and insert update or delete operations on the database..

But in the wordpress we just need a single line for the opration and no need to connect to database. Because this steps are done at the installation only.

INSERT QUERY :

$wpdb->insert( $table, $data, $format );

table (string):

The name of the table.

data (array):

Data to insert in column => value pairs.

format (array|string) : (optional)

An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.

 

UPDATE QUERY :

$wpdb->update( $table, $data, $where, $format = null, $where_format = null );

table (string) :

The name of the table to update.

data (array) :

Data to update in column => value pairs.

where (array) :

A named array of WHERE clauses in column => value pairs. Multiple clauses will be joined with ANDs.

format (array|string) :(optional)

An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data.

where_format (array|string) : (optional)

An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where.

Possible format values:

%s as string; %d as decimal number and %f as float. If omitted, all values will be strings.

 

DELETE QUERY :

$wpdb->query(‘query’);

query (string) :

The SQL query you wish to execute for deletion.

 

Its really very easy to play with database in the WordPress.

Start to do that and enjoy coding.

hiii friends... i am doing msc in computer application and information technology. we are here to share our knowledge and idea on shareprogrammingtips.com.

2 Comments to Insert update and delete in WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*