我有php网站和wordpress网站。我想在我的wordpress网站上连接php网站数据库。
我试过这样的
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);
数组() 警告:无法修改标头信息 - 已由
发送的标头我需要在我的主题中显示表数据。怎么可能?请帮帮我。
答案 0 :(得分:1)
尝试不定义变量。 或更改您的变量名称
试试这个
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);
或试试这个
$second_db = new wpdb('myusername', 'mypassword', 'mydbname', 'my-host');
$your_query = "SELECT * FROM DOCTORS";
$results = $second_db->get_results($your_query);
print_r($results);