You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
Hi Nick
I have set up an alternate database connection in the software.
Is there any straightforward ways to tell the software I want the functions to use the alternate database connection.
For example, using functions such as $this->CORE_DB->sql_do for the alternate database.
I know when the CORE_DB is loaded, it includes 'CORE_DB_1'.
Does that mean I can use $this->CORE_DB_1->... for the alternate database??
Thanks
Rob
Offline
The software by default uses the primary database connection. Assuming you have set up an alternate connection, and you want to use that in a web page in K9 to pull data from a table in a different database, you'd add code like this to your web page:
<?php // +-- // | Load objects we'll need and set the id from core_altrdbms for the // | alternate connection. // +-- $this->CORE_DB =& $this->quick_object('CORE_DB','core','CORE_DB_1'); $this->CORE_Crypt =& $this->quick_object('CORE_Crypt','core'); $dsnid = 'ALTERNATE_DB_ID'; // +-- // | Pull the alternate db info from the core_altrdbms table. // +-- $sql = 'SELECT dbtype, hostname, dbname, username, dbpassword FROM core_altrdbms WHERE id=" . $this->CORE_DB->quote($dsnid); $result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_altrdbms', 'order' => array('id' => 'ASC'))); // +-- // | Construct the DSN for the alternate connection. // +-- $dsn = $result[0]; $dsn['password'] = $this->CORE_Crypt->decrypt($dsn['dbpassword']); unset($result[0]['dbpassword']); // +-- // | Connect to the alternate database. // +-- $this->CORE_DBX =& $this->load_object(array('app' => 'core', 'class' => 'CORE_DB', 'version' => '9.0.0', 'name' => 'CORE_DB_2', 'construct' => $dsn)); $this->CORE_DBX->connect(); // +-- // | Do something. // +-- $sql = 'SELECT * FROM tablename'; $result = $this->CORE_DBX->sql_do(array('sql' => $sql, 'table' => 'tablename', 'order' => array('id' => 'ASC'))); foreach ($result as $num => $data) {} // +-- // | Disconnect from the alternate database. // +-- $this->CORE_DBX->disconnect(); $this->destroy_object('CORE_DB_2'); ?>
Offline
Perfect.
Order tables are now moved to different database via daily cron job.
Alternate database is only accessed when running backend finance reports and backend order search.
Account holders can opt to search orders older than 12 months in the account history.
Thank you
Offline