Connect Additional Databases
We no longer maintain the Knowledge Base since version 4.3.x. All the latest user and developer documentation for 4.3.x and newer versions is now available at docs.cs-cart.com.
- This article applies to CS-Cart versions:
It is sometime necessary to use an additional database connection to get external data, for replication, backup, or other purposes. CS-Cart has a convenient developer method to establish connections to database hosts different from the default one, which is strictly defined in the core.
- db_initiate - Use this method to establish a connection with a database on an external host.
db_initiate(<hostname>, <user>, <password>, <db_name>, <alias>, <table_prefix>);
- hostname - Target hostname (i.e. localhost)
- user - Target database access username
- password - Target database access password
- db_name - Target database name
- alias - Local alias to determine the target database
- table_prefix - Prefix for the target database table names. Replaces the "?:" placeholder
db_initiate('localhost', 'mysqluser', 'mysqlpassword', 'cscart_backup', 'bckp', 'cscart_'); $data = db_get_array("bckp#SELECT * FROM ?:products");
In this example $data will contain data from the cscart_products table of the cscart_backup database, which is hosted on localhost.
|<< Read previous||Read next >>|