Get data from another database into Wordpress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $wpdbtest_otherdb = new wpdb('db_user', 'db_password', 'db_name', 'localhost');
  3. $wpdbtest_otherdb->show_errors();
  4. $datarows = $wpdbtest_otherdb->get_results("SELECT field,field2,field3 FROM table");
  5.  
  6. foreach ($datarows as $datarow) {
  7. echo $datarow->field;
  8. }
  9. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.