Show Menu
Cheatography

WordPress $wpdb Cheat Sheet by

$wpdb functions syntax

$wpdb-­>ge­t_var

$wpdb-­>ge­t_var( 'query' );
$wpdb-­>ge­t_var( 'query', column­_of­fset, row_offset );
Ex: $user_­count = $wpdb-­>ge­t_var( "­SELECT COUNT(*) FROM $wpdb-­>us­ers­" );

$wpdb-­>ge­t_row

$wpdb-­>ge­t_r­ow(­'qu­ery', output­_type, row_of­fset);
OBJECT - result will be output as an object.
ARRAY_A - result will be output as an associ­ative array
ARRAY_N - result will be output as a numeri­cally indexed array.

$wpdb-­>ge­t_col

$wpdb-­>ge­t_col( 'query', column­_offset );

$wpdb-­>ge­t_r­esults

$wpdb-­>ge­t_r­esults( 'query', output­_type );
OBJECT - result will be output as a numeri­cally indexed array of row objects.
OBJECT_K - result will be output as an associ­ative array of row objects, using first column's values as keys (dupli­cates will be discarded).
ARRAY_A - result will be output as a numeri­cally indexed array of associ­ative arrays, using column names as keys.
ARRAY_N - result will be output as a numeri­cally indexed array of numeri­cally indexed arrays.

$wpdb-­>insert

$wpdb-­>in­sert( $table, $data, $format );

$wpdb-­>re­place

$wpdb-­>re­place( $table, $data, $format );

$wpdb-­>update

$wpdb-­>up­date( $table, $data, $where, $format = null, $where­_format = null );

$wpdb-­>delete

$wpdb-­>de­lete( $table, $where, $where­_format = null );

$wpdb-­>query

$wpdb-­>qu­ery­('q­uery');

$wpdb-­>pr­epare

$sql = $wpdb-­>pr­epare( 'query' , value_­par­ame­ter[, value_­par­ameter ... ] );

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets