dtm41506 2014-10-28 07:12
浏览 36
已采纳

在我的wp站点中获取另一个数据库内容

I have php site and a wordpress site. I want to connect the php site db in my wordpress site.

I have tried like this

define('DB_NAME', 'mydbname');
define('DB_USER', 'myusername');
define('DB_PASSWORD', 'mypassword');
define('DB_HOST', 'my-host');
$second_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$your_query = "SELECT * FROM DOCTORS";
$results = $second_db->get_results($your_query);
print_r($results);

Array ( ) Warning: Cannot modify header information - headers already sent by

I need the table data display in my theme. How can it be possible ? Please help me.

  • 写回答

1条回答 默认 最新

  • duanbishai5271 2014-10-28 07:21
    关注

    Try without define variables. or change your variable names

    Try this

    define('DB_NAME_1', 'mydbname');
    define('DB_USER_1', 'myusername');
    define('DB_PASSWORD_1', 'mypassword');
    define('DB_HOST_1', 'my-host');
    $second_db = new wpdb(DB_USER_1, DB_PASSWORD_1, DB_NAME_1, DB_HOST_1);
    $your_query = "SELECT * FROM DOCTORS";
    $results = $second_db->get_results($your_query);
    print_r($results);
    

    OR Try with this

    $second_db = new wpdb('myusername', 'mypassword', 'mydbname', 'my-host');
    $your_query = "SELECT * FROM DOCTORS";
    $results = $second_db->get_results($your_query);
    print_r($results);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测