0

I have two different systems running on my server. Wordpress for website and opencart for web shop. What i would like to do is fetch some of the latest products from shop database to show on my website.

How is the wordpress with selecting from another database? It is just a few lines of data, what should i do? Do a direct call inside the template files? Alter the existing config files?

4

1 回答 1

1

如此处所述http://www.davidtan.org/wordpress-how-to-use-wpdb-class-to-connect-fetch-data-from-another-database/,您可以使用:

$mydb= new wpdb('user','pass','mydb','localhost');
$rows = $mydb->get_results("select columnName from tableName");
foreach ($rows as $obj) {
    echo $obj->columnName;
}
于 2013-04-11T11:25:47.270 回答