Created
June 14, 2019 08:07
-
-
Save junaidtk/9a2ea30a41c1b00aec5fdb6a90acb261 to your computer and use it in GitHub Desktop.
WPDB Common functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wpdb->get_row() | |
==================== | |
get_row() returns single row of data from database table. | |
eg: | |
<?php | |
$mycustomer = $wpdb->get_row(“SELECT * FROM laundry_customers WHERE ID = 1”); | |
echo $mycustomer -> customer_name; | |
?> | |
$wpdb->get_results() | |
===================== | |
get_results() returns multiple rows of data from database table if present. It returns 0 if no row is selected. | |
<?php | |
$allcustomers = $wpdb->get_results(“SELECT customer_name FROM laundry_customers WHERE status = 1”); | |
$wpdb->get_var() | |
==================== | |
get_var() retrieves single value from database table. It returns NULL if no result is found. | |
<?php | |
$customer_count = $wpdb->get_var(“SELECT COUNT(*) FROM laundry_customers;”); | |
echo ‘<p>Total customer: ‘ . $customer_count . ‘</p>’; | |
?> | |
$wpdb->get_query() | |
=============== | |
returns 1 if any error return FALSE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment