Created
November 1, 2014 07:50
-
-
Save rvgpl/b62f1d98e297d6fae917 to your computer and use it in GitHub Desktop.
Query external database from Wordpress
This file contains 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
################################################################################################### | |
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