First you need to add the connection information of the other database. This way you can use drupal database abstraction layer for altering any database.
Source code viewer
'driver' => 'mysql', 'database' => 'my_database', 'username' => 'root', 'password' => '', 'host' => 'localhost', )); // Run select query on table data. $results = Database::getConnection('default', 'mydb') ->select('data', 'd') ->fields('d') ->execute() ->fetchAll(); // Iterate through results. foreach($results as $result) { // Alter results. foreach($fields as &$field) { } // Save the data back. try { $count = Database::getConnection('default', 'mydb') ->update('data') ->fields($fields) ->condition('publicationid', $result->publicationid) ->execute(); } catch (Exception $e) { drupal_set_message(t('Query failed message = %message, query= %query', } }Programming Language: PHP