admin管理员组文章数量:1415111
I want to connect my Wordpress website 1 to database from Wordpress website 2.
Here is my code:
<?php
$myotherdatabase = new wpdb("username","password","databasename","localhost");
$motscles = "abri";
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = 'nom' AND MATCH (`meta_value`) AGAINST ('" . $motscles . "' IN BOOLEAN MODE)";
$result = $myotherdatabase -> get_results($query, ARRAY_A);
foreach ($result as $post) {
$pids .= $post['post_id'] . ",";// ARRAY_A
}
echo $pids;
?>
The result is empty. If I run the same query directly on Wordpress website 2, it works.
Therre is something wrong in my code? Or do you think the problem may come from hosting?
Thank you
EDIT: The problem came from the hosting. There is a restriction, I can not connect to the website 2 database from website 1.
I want to connect my Wordpress website 1 to database from Wordpress website 2.
Here is my code:
<?php
$myotherdatabase = new wpdb("username","password","databasename","localhost");
$motscles = "abri";
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = 'nom' AND MATCH (`meta_value`) AGAINST ('" . $motscles . "' IN BOOLEAN MODE)";
$result = $myotherdatabase -> get_results($query, ARRAY_A);
foreach ($result as $post) {
$pids .= $post['post_id'] . ",";// ARRAY_A
}
echo $pids;
?>
The result is empty. If I run the same query directly on Wordpress website 2, it works.
Therre is something wrong in my code? Or do you think the problem may come from hosting?
Thank you
EDIT: The problem came from the hosting. There is a restriction, I can not connect to the website 2 database from website 1.
Share Improve this question edited Aug 26, 2019 at 6:16 Bertrand asked Aug 22, 2019 at 5:22 BertrandBertrand 11 bronze badge 1- Do you run the same script, or just the SELECT query in phpMyAdmin e.g. on your website 2? Is the 'wp_' prefix correct in website 2? – moped Commented Aug 22, 2019 at 7:50
1 Answer
Reset to default 0Use code as below :
<?php
$myotherdatabase = new wpdb("username","password","databasename","localhost");
$motscles = "abri";
$query = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = 'nom' AND MATCH (`meta_value`) AGAINST ('" . $motscles . "' IN BOOLEAN MODE)";
$result = $myotherdatabase -> get_results($query, ARRAY_A);
foreach ($result as $post) {
$pids .= $post->post_id . ",";// ARRAY_A
}
echo $pids;
?>
本文标签: databaseTroubles when I want to connect to another DB
版权声明:本文标题:database - Troubles when I want to connect to another DB 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214728a2648094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论