1

I'm trying to connect and select some data from an external DB. The DB is in the same server as WP, so it has the same username and password, but different DB name. Here's what I'm using to connect to DB:

$db_name = "class";                  
$class_mydb = new wpdb ( DB_USER, DB_PASS, $db_name, DB_HOST );
$class_mydb -> show_errors();

Then, I'm trying to get some data, using get_results:

$class_rows = $class_mydb -> get_results( "SELECT * FROM `class-table`" );
foreach ( $class_rows as $classes ) {
    echo "<p>" . $class -> Column_Name . "</p>";
}

Why do I always get this warning message?

Warning: Invalid argument supplied for foreach()

  • Basic debugging. What is var_dump($class_rows);? – s_ha_dum Dec 12 '15 at 16:11
0

Sorry fellows, it was a mysql issue. Nothing wrong with the code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.