[support] Using two databases

Morbus Iff morbus at disobey.com
Mon Dec 11 23:38:13 UTC 2006


/**
   * Issues a db_query() against the CiviCRM database.
   */
function civicrm_db_query($query) {
    global $db_url;                    // normally Drupal's DSN.
    $original_url = $db_url;           // we'll save it off temporarily.
    $db_url = CIVICRM_DSN;             // set it to the CiviCRM DSN.
    db_set_active('civicrm');          // then make CiviCRM active.
    $args = func_get_args();           // load all the args passed.
    array_shift($args);                // shove off the SQL query.
    $result = db_query($query, $args); // make the query against CiviCRM.
    $db_url = $original_url;           // toggle back to Drupal's DSN.
    db_set_active('default');          // and make that active again.
    return $result;                    // return CiviCRM database result.
}

-- 
Morbus Iff ( all of the above - the only checkbox worth checking )
Technical: http://www.oreillynet.com/pub/au/779
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus


More information about the support mailing list