admin管理员组文章数量:1387398
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 badges3 Answers
Reset to default 4It 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
本文标签: How to use multiple database in wordpress
版权声明:本文标题:How to use multiple database in wordpress? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744546979a2611956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论