Using PHP Code Snippets to query a database, $dbconnection->get_results is outputting nothing


I’m currently trying to run this php code snippet in a WordPress Page using a PHP code snippet extension.

//Database connection script
//Connecting to our master database
 global $wpdb;
 $hostname = "host";
 $username = "user";
 $password = "pass";
 $dbname = "dbname";

 //creating new database object
 $dbconnection = new $wpdb($username, $password, $dbname, $hostname );
 //Querying the database
 $dbconnection->show_errors( true );
 $dbQuery = $dbconnection ->get_results("SELECT * FROM Master");

The output on the page looks like this, the table headers are there because of html code. The goal is to eventually get the data properly formatted under them but for now I’m getting no results from the database. The database is a separate database from the automatically generated WordPress one created through PhPMyAdmin, so the only thing I can think of is that my new wpdb object might be wrong but I made sure to double/triple check the information. I’ve been stuck on this for hours because I’m getting no errors either through print_error. enter image description here

Francis Brideau 2 years 2022-03-22T01:07:50-05:00 0 Answers 0 views 0

Leave an answer