I am bulding a drupal7 site then i want to fetch some data from another website database. so how to link another website database in drupal 7.
There are some tricks which are following:
First goto "setting.php" file of drupal 7 site then make some changes in setting.php which are below:
<?php
$databases = array(
'drupal_site_database' => array(
'default' => array(
'database' => 'drupalsite',
'username' => 'test',
'password' => 'test',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
'another_site_database' => array(
'default' => array(
'database' => 'anothersite',
'username' => 'test',
'password' => 'test',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
?>
In Second step write query in drupal site which are below:
<?php
db_set_active('another_site_database');
// here you can write query for fetching data.
db_set_active('drupal_site_database');
?>
There are some tricks which are following:
First goto "setting.php" file of drupal 7 site then make some changes in setting.php which are below:
<?php
$databases = array(
'drupal_site_database' => array(
'default' => array(
'database' => 'drupalsite',
'username' => 'test',
'password' => 'test',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
'another_site_database' => array(
'default' => array(
'database' => 'anothersite',
'username' => 'test',
'password' => 'test',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
?>
In Second step write query in drupal site which are below:
<?php
db_set_active('another_site_database');
// here you can write query for fetching data.
db_set_active('drupal_site_database');
?>
Nice blog, keep sharing with us.
ReplyDeleteDrupal Course in Chennai
Drupal Course in Bangalore