mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-09 13:06:14 +00:00
log all sql statements into file if log file is given
This commit is contained in:
parent
46582a2be4
commit
4265c965de
|
@ -92,6 +92,16 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
*/
|
*/
|
||||||
private $_intransaction;
|
private $_intransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string set a valid file name for logging all sql queries
|
||||||
|
*/
|
||||||
|
private $_logfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var resource file pointer of log file
|
||||||
|
*/
|
||||||
|
private $_logfp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of all database tables
|
* Return list of all database tables
|
||||||
*
|
*
|
||||||
|
@ -139,6 +149,13 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
$this->_user = $user;
|
$this->_user = $user;
|
||||||
$this->_passw = $passw;
|
$this->_passw = $passw;
|
||||||
$this->_connected = false;
|
$this->_connected = false;
|
||||||
|
$this->_logfile = '';
|
||||||
|
if($this->_logfile) {
|
||||||
|
$this->_logfp = fopen($this->_logfile, 'a+');
|
||||||
|
if($this->_logfp)
|
||||||
|
fwrite($this->_logfp, microtime()." BEGIN ------------------------------------------\n");
|
||||||
|
} else
|
||||||
|
$this->_logfp = null;
|
||||||
// $tt*****id is a hack to ensure that we do not try to create the
|
// $tt*****id is a hack to ensure that we do not try to create the
|
||||||
// temporary table twice during a single connection. Can be fixed by
|
// temporary table twice during a single connection. Can be fixed by
|
||||||
// using Views (MySQL 5.0 onward) instead of temporary tables.
|
// using Views (MySQL 5.0 onward) instead of temporary tables.
|
||||||
|
@ -154,6 +171,24 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
$this->_debug = false;
|
$this->_debug = false;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of SeedDMS_Core_DatabaseAccess
|
||||||
|
*
|
||||||
|
* Sets all database parameters but does not connect.
|
||||||
|
*
|
||||||
|
* @param string $driver the database type e.g. mysql, sqlite
|
||||||
|
* @param string $hostname host of database server
|
||||||
|
* @param string $user name of user having access to database
|
||||||
|
* @param string $passw password of user
|
||||||
|
* @param string $database name of database
|
||||||
|
*/
|
||||||
|
function __destruct() { /* {{{ */
|
||||||
|
if($this->_logfp) {
|
||||||
|
fwrite($this->_logfp, microtime()." END --------------------------------------------\n");
|
||||||
|
fclose($this->_logfp);
|
||||||
|
}
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to database
|
* Connect to database
|
||||||
*
|
*
|
||||||
|
@ -234,6 +269,9 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
function getResultArray($queryStr) { /* {{{ */
|
function getResultArray($queryStr) { /* {{{ */
|
||||||
$resArr = array();
|
$resArr = array();
|
||||||
|
|
||||||
|
if($this->_logfp) {
|
||||||
|
fwrite($this->_logfp, microtime()." ".$queryStr."\n");
|
||||||
|
}
|
||||||
$res = $this->_conn->query($queryStr);
|
$res = $this->_conn->query($queryStr);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
if($this->_debug)
|
if($this->_debug)
|
||||||
|
@ -256,6 +294,9 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
* @return boolean true if query could be executed otherwise false
|
* @return boolean true if query could be executed otherwise false
|
||||||
*/
|
*/
|
||||||
function getResult($queryStr, $silent=false) { /* {{{ */
|
function getResult($queryStr, $silent=false) { /* {{{ */
|
||||||
|
if($this->_logfp) {
|
||||||
|
fwrite($this->_logfp, microtime()." ".$queryStr."\n");
|
||||||
|
}
|
||||||
$res = $this->_conn->exec($queryStr);
|
$res = $this->_conn->exec($queryStr);
|
||||||
if($res === false) {
|
if($res === false) {
|
||||||
if($this->_debug)
|
if($this->_debug)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user