Connecting to multiple Databases

Discussion in 'Drupal' started by krishmadutta, Sep 18, 2009.

  1. #1
    Hi

    I am trying to connect to 2 database within drupal. Need is to save Drupal forms information (Username/ Company/ City) in non Drupal database to generate reports. I saw on drupal website this can be achived by adding database to settings.php
    So I added :-
    $db_url['default'] = 'mysql://drupaluser:drupal@localhost:3306/drupal6';
    $db_url['test'] = 'mysql://drupaluser:drupal@localhost:3306/test';

    Now I go to content > Form and under Additional Processing of webform I add following code
    <?php
    db_set_active('test');

    try {
    mysql_query("INSERT INTO test (username, company, city)
    VALUES ('Peter', '35', 'XXXXXX')");

    mysql_query("INSERT INTO test (username, company, city)
    VALUES ('Glenn', '33', 'YYYYYY')");
    } catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
    }
    echo "Insertion Complete";
    mysql_close($con);
    db_set_active('default');
    ?>

    But it doesn't work. Any Idea what I am missing??

    Thank you in advance
     
    krishmadutta, Sep 18, 2009 IP