dsm0688 2014-03-03 15:23
浏览 19

试图查询远程WordPress数据库

I'm trying to retrieve some data from a remote Wordpress site (to another Wordpress site), the code below returns an empty array, if I use the local database (just comment out the first line of code) it returns posts. Preferably I'd like to be able to run a WP_Query on the remote database, but that's just a bonus.

        $wpdb = new wpdb( $dbusername, $dbpassword, $dbname, $dbhost );

        $wpdb->set_prefix('wp_');
        $wpdb->show_errors();

        $psts = $wpdb->get_row( 
            "SELECT * FROM $wpdb->posts"
        );

EDIT: I've discovered that if I change the query to "SELECT * FROM wp_posts" I get a result. So I guess it's a PHP version thing (I run 5.4.4 and server runs 5.3.3)? Still can't run a WP-Query though.

EDIT 2: I just realized I've left out one important piece of information: the site I'm running the Query from is a multi site install! I'm sure this could affect they how the querys are formed!

  • 写回答

4条回答 默认 最新

  • duanmao7553 2014-03-03 16:22
    关注

    Check if:

    • Remote DB is reachable
    • Your user has rights on the remote DB/Table
    • Your Remote DB is not only accessible by localhost (if so, enter a % instead of localhost)
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算