[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[182] trunk/0.3/cs_phpDB.class.php
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2010-09-01 14:07:59
|
Revision: 182 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=182&view=rev Author: crazedsanity Date: 2010-09-01 14:07:52 +0000 (Wed, 01 Sep 2010) Log Message: ----------- Ability to write all SQL queries to a file. /cs_phpDB.class.php: * MAIN::: -- NEW (protected) ARG: $fsObj -- NEW (protected) ARG: $logFile -- NEW (protected) ARG: $writeCommandsToFile * __construct(): -- ARG CHANGE: NEW ARG: #2 ($writeCommandsToFile=null) -- updated header -- added option to write all queries to a log file, whose name can be specified (i.e. $writeCommandsToFile=myfile.txt) -- logic to create a file if one not present * __call(): -- write data to a file if method was 'exec' and internal var, writeCommandsToFile, has been set. Modified Paths: -------------- trunk/0.3/cs_phpDB.class.php Modified: trunk/0.3/cs_phpDB.class.php =================================================================== --- trunk/0.3/cs_phpDB.class.php 2010-07-31 17:50:13 UTC (rev 181) +++ trunk/0.3/cs_phpDB.class.php 2010-09-01 14:07:52 UTC (rev 182) @@ -31,9 +31,21 @@ private $dbType; public $connectParams = array(); protected $gfObj; + protected $fsObj; + protected $logFile; + protected $writeCommandsToFile; //========================================================================= - public function __construct($type='pgsql') { + /** + * + * @param string $type + * @param bool $writeCommandsToFile (change this to a string for a filename, + * or use boolean true and it write to + * a default filename (__CLASS__.log). + * @return unknown_type + */ + public function __construct($type='pgsql', $writeCommandsToFile=null) { + if(is_null($type) || !strlen($type)) { $type = 'pgsql'; } @@ -46,6 +58,21 @@ parent::__construct(true); $this->isInitialized = TRUE; + + $this->writeCommandsToFile = $writeCommandsToFile; + + if($this->writeCommandsToFile) { + $this->logFile = __CLASS__ .".log"; + if(is_string($this->writeCommandsToFile)) { + $this->logFile = $this->writeCommandsToFile; + } + $this->fsObj = new cs_fileSystem(constant('RWDIR')); + $lsData = $this->fsObj->ls(); + if(!isset($lsData[$this->logFile])) { + $this->fsObj->create_file($this->logFile); + } + $this->fsObj->openFile($this->logFile, 'a'); + } }//end __construct() //========================================================================= @@ -67,6 +94,11 @@ array_pop($this->queryList); } array_unshift($this->queryList, $args[0]); + + //log it to a file. + if($this->writeCommandsToFile) { + $this->fsObj->append_to_file(date('D, d M Y H:i:s') . ' ('. microtime(true) . ')::: '. $args[0]); + } } $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |