Core/setDbConnection

From PunchCMS
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);