Skip to main content

How to use another site database in drupal7?

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');
?>

Comments

Post a Comment

Popular posts from this blog

How to configure memcache with drupal 8 on ubuntu for reduce page load?

Memcache is an in-memory (RAM). It store data in Key-Value Format. Memcached server automatically stores all the content (data) in allocated RAM on the server. After configure memcache, it increase Drupal Site performance by moving standard caches out of the database. Drupal does not come with memcache by default if we want to install it then we have to install it on server. There are many steps that how to install memcache on the server and how to configure it with drupal 8 for reducing the load on the database with every page request. Step1 :- Open terminal of your machine and run following commands :- a. sudo apt-get update b. sudo apt install memcached c. sudo apt install php-memcached Step2 :- Check that Memcache daemon is working by using the following command : a. "ps aus | grep memcached" Step3 :- Also, check Memcache extension is configured in PHP. For that you have create a file phpinfo.php then write below code. <?php phpinfo(); ?> or sudo vi /var/www/html...

How to use insert,update and delete query in drupal6 and drupal7?

INSERT STATEMENT <?php   // Drupal 6   db_query("INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)", 5, 'hello world', 3.14);   // Drupal 7   $id = db_insert('mytable')           ->fields(array('intvar' => 5,'stringvar' => 'hello world','floatvar' => 3.14))           ->execute(); ?> UPDATE STATEMENT. <?php   //Drupal 6   db_query("UPDATE {node} SET title='%s', status=%d WHERE uid=%d", 'hello world', 1, 5);   //Drupal 7   db_update('node')     ->fields(array('title' => 'hello world', 'status' => 1))     ->condition('uid', 5)     ->execute(); ?> DELETE STATEMENT. <?php   //Drupal 6   db_query("DELETE FROM {node} WHERE uid=%d AND created < %d", 5, REQUEST_TIME - 3600);   //Drupal 7   db_delete('node')     ->condition('uid', ...

How deploy your angular project on GitHub Pages

Step 1:- Create Repository on github Note :- Open terminal and goto your project direcoty then run following command which you got after created repository. Step 2:- git init Step 3:- git add . Step 4:- git commit -m "first commit" Step 5:- git branch -M main Step 6:- git remote add origin https://github.com/rahuldrupal5788/DevR9angular.git Step 7:- git push -u origin main Step 8:- We need to build our code in production mode for that we will create deployment files that will be deployed on GitHub Pages. By default, this deployment code is generated in the /dist/<ProdectName> folder under the angular project folder, but we need to generate this in the "docs" folder under the angular project folder. So, we need to make a small change in the angular.json file and change the outputpath value to "docs/". Step 9:- Run the following command with the baseHref  option in the git bash window to generate deployment files in the docs folder. ng build --prod --b...