Skip to content

Instantly share code, notes, and snippets.

@rvgpl
Created November 1, 2014 07:50
Show Gist options
  • Save rvgpl/b62f1d98e297d6fae917 to your computer and use it in GitHub Desktop.
Save rvgpl/b62f1d98e297d6fae917 to your computer and use it in GitHub Desktop.
Query external database from Wordpress
###################################################################################################
Query regular Wordpress database
###################################################################################################
//Declaring $wpdb as global and using it to execute an SQL query statement that returns a PHP object
global $wpdb;
$result = $wpdp->get_results('SELECT * FROM wp_options, OBJECT);
########################################################################################################
Querying a different database
########################################################################################################
//Create a new wpdb variable with other database connect values and use it to execute SQL query statement that return a PHP Object
$newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
$newdb->get_results('SELECT * FROM users, OBJECT');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment