最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use multiple database in wordpress?

programmeradmin1浏览0评论

I want to fetch some post from another wordpress site which is hosted in the same server. How can I fetch those post?

Is multiple database connection is possible in wordpress?

I want to fetch some post from another wordpress site which is hosted in the same server. How can I fetch those post?

Is multiple database connection is possible in wordpress?

Share Improve this question edited Sep 22, 2012 at 13:48 Brian Fegter 10k1 gold badge41 silver badges60 bronze badges asked Sep 22, 2012 at 6:59 soumendusoumendu 451 gold badge1 silver badge5 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 4

It is possible but you must manually create a new instance of the wpdb class with right settings for your other database.

Quote from the wpdb Codex page:

The $wpdb object can talk to any number of tables, but only one database: the WordPress database. In the rare case you need to connect to another database, you will have to instantiate your own object from the wpdb class with the appropriate connection details. For extremely complicated setups with many databases, consider using hyperdb instead.

You can use HyperDB: https://wordpress/plugins/hyperdb/ It allows multiple databases, also read/write replicas or master / slave.

1) Download class db at link: https://codeshack.io/super-fast-php-mysql-database-class/ - rename class db = db_custom

2) .../themes/theme-name/functions.php

$dbhost = 'db_ip'; // 127.0.0.1 $dbuser = 'db_user'; // input database username $dbpass = 'db_user_password'; // input your database password $dbname = 'db_user_name'; // input your datatabase name

$db_watch = new db_custom($dbhost, $dbuser, $dbpass, $dbname); $sql = "SELECT * FROM products LIMIT 0,2"; $results = $db_watch->query($sql)->fetchAll(); print_r($results);

I have tested my website WordPress it's working well

发布评论

评论列表(0)

  1. 暂无评论