0

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.

user3747821
  • 21
  • 1
  • 8

1 Answers1

1

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);
Yatendra
  • 1,310
  • 1
  • 18
  • 31