Core/setDbConnection

From PunchCMS
Revision as of 22:45, 25 December 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PCMS_Client->setDbConnection([reInit])

Overview

Reset the internal database connection. Because of the singleton setup of the database connection it needs to be reset after working with a different database than the CMS database. This could be considered a MDB2 bug.

Arguments

reInit [boolean, optional]
TRUE re-initialize the connection, FALSE will only reset it using the singleton method. Default is FALSE.

Returns

Nothing.

Example

$objCms = PCMS_Client::getInstance();
 
// Write a log entry to a client specific database.
$intPageId = $objCms->getAliasId();
$objLog = DB_DataObject::factory('weblog');
$objLog->page = $intPageId;
$objLog->date = date();
$objLog->insert();
 
// Now we have to re-initialize the connection for the CMS object.
$objCms->setDbConnection(TRUE);