How to run mysql queries in wordpress

At some point in your WordPress development career you may be presented with the need to write some custom mysql queries.

Select Query

Single row fetching

$ures = $wpdb->get_row("SELECT * F ROM `custome_users` ORDER BY `id` DESC");
    $ures ->name;

Multiple rows fetching

$ures = $wpdb->get_results("SELECT * F ROM `custome_users` ORDER BY `id` DESC");					
foreach ($ures as $uresfet)
{
    $uresfet->name;
}

How to count total number of rows

 $ures = $wpdb->get_results("SELECT * F ROM `custome_users` ORDER BY `id` DESC");
 $rows=$wpdb->num_rows;

Delete Query

 $wpdb->query("DELETE F ROM custome_users where id='$deleteid'");

Update query

 $wpdb->query("UPDATE `sample_requests` SET `firstname` = '$firstname', `lastname` = '$lastname' WHERE `id` ='$id'");

Leave a Reply

Related Posts: You may like

Extract Total Number of Image And Missing Alt Attribute using php

How to track contact form 7 form in salesforce without plugin

Contact Form 7 Redirect to Thank You Page

How to Validation Business Email in Contact Form 7 WordPress

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.