how do we insert data into external database in apigee dev portal

I need to add some data after submitting a form to an external database and need to retreive someother data from another external databases.

That means i need to connect to different databases and insert/display the data in apigee devportal . Kindly let me know if anyone has tried / implemented this approach

Solved Solved
0 2 514
1 ACCEPTED SOLUTION

Hi @Ramya - this answer assumes you are using the Drupal-based DevPortal.

In this case, you can define additional database connections in your settings.php file. Typically this would include hostname, port, username and password, as well as a unique name for the connection. For example:

$databases['my_external_db']['default'] = array(
'driver' => 'mysql', 'database' => 'forum', 'username' => 'username', 'password' => 'password', 'host' => 'mysql.host.com', 'port' => 3306, );

Then you can make queries against this external database directly using syntax like

Database::getConnection('my_external_db', 'default')->select($table_name, $table_alias)-> ... ->execute();

If you need to do a lot of queries, you can use this instead:

db_set_active('my_external_db');
// Now any db_query() or other db_* functions will run against the external db.
db_set_active(); // sets active connection back to default Drupal database.

View solution in original post

2 REPLIES 2

Hi @Ramya - this answer assumes you are using the Drupal-based DevPortal.

In this case, you can define additional database connections in your settings.php file. Typically this would include hostname, port, username and password, as well as a unique name for the connection. For example:

$databases['my_external_db']['default'] = array(
'driver' => 'mysql', 'database' => 'forum', 'username' => 'username', 'password' => 'password', 'host' => 'mysql.host.com', 'port' => 3306, );

Then you can make queries against this external database directly using syntax like

Database::getConnection('my_external_db', 'default')->select($table_name, $table_alias)-> ... ->execute();

If you need to do a lot of queries, you can use this instead:

db_set_active('my_external_db');
// Now any db_query() or other db_* functions will run against the external db.
db_set_active(); // sets active connection back to default Drupal database.

Perfect thanks a lot Karl