我想将我的Wordpress网站1连接到Wordpress网站2的数据库。
这是我的代码:
<?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;
?>
结果为空。如果我直接在Wordpress网站2上运行相同的查询,它就会工作。
我的代码有问题吗?或者你认为问题可能来自托管?
非常感谢。
编辑:问题来自主机。有一个限制,我无法从网站1连接到网站2数据库。
SO网友:Pratikb.Simform
使用代码如下:
<?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;
?>