How to use WPDB class for DB access

require_once ‘../../../wp-load.php’;

function insertDB($name,$contact,$email,$evtName) {
global $wpdb;
$wpdb->custom_table = “custom_table_name”;

//$wpdb->show_errors();

$ok = $wpdb->insert($wpdb->custom_table, array(
‘name’ => $name,
‘contact’ => $contact,
‘email’ => $email,
‘event_name’ => $evtName
));

if ($ok) {
echo json_encode(array( ‘ok’ => true , ‘status’ => ‘success in DB insert’ ));
}else {
//$wpdb->print_error();
echo json_encode(array( ‘ok’ => false , ‘status’ => ‘failed on DB insert’ ));
}

}

insertDB($name,$contact,$email,$evtName);

Advertisement

About kaixersoft

Proud to be Pinoy. Batangueno in nature. Love to see and write computer codes. View all posts by kaixersoft

One Response to “How to use WPDB class for DB access”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.