Connecting Additional Databases in Venddor IO

Setting Up External Database Connections

At times, leveraging data from an auxiliary database or conducting operations like replication and backup becomes essential. Venddor IO offers developers a streamlined approach to link with database hosts distinct from its core-defined default.

External database connections can be useful for scenarios such as connecting to legacy systems, importing data from other platforms, or maintaining separate databases for specific business functions.

Methods for Database Connections

To facilitate connections with an external database, you can utilize the following methods:

1. Initializing Database Connection: db_initiate

This method sets up a connection to an external database host.

Usage:

db_initiate($host, $user, $password, $name, $params = array());

Parameters:

2. Switching Database Connection: db_connect_to

This method allows shifting between different databases once connected.

Usage:

db_connect_to($params, $name);

Parameters:

Shifting to a Different Database

In some scenarios, you might need to redirect your queries to another database. With Venddor IO's robust functionality, it becomes effortless to target a new database after setting up its connection.

Example: Connecting to a Backup Database

$params = array(
    'dbc_name' => 'backup',
    'table_prefix' => 'venddor'
);

db_initiate('localhost', 'db_user', 'db_password', 'venddor_backup', $params);
db_connect_to($params, 'venddor_backup');

$data = db_get_array("SELECT * FROM ?:products");

In this example, the $data variable will extract its content from the venddor_products table present in the venddor_backup database on localhost.

This ability empowers developers to seamlessly transition between databases within the Venddor IO framework, ensuring flexibility and effective data management. Whether you're pulling from backup databases or any other secondary sources, Venddor IO ensures smooth operations.

Always ensure proper security measures when connecting to external databases. Use dedicated database users with appropriate permissions and avoid storing credentials in version-controlled files.