diff --git a/oc-includes/osclass/Logger/LogDatabase.php b/oc-includes/osclass/Logger/LogDatabase.php index b6d9eb884c..bf5485d3f6 100755 --- a/oc-includes/osclass/Logger/LogDatabase.php +++ b/oc-includes/osclass/Logger/LogDatabase.php @@ -157,8 +157,41 @@ function writeMessages() fwrite($fp, '--------------------------------------------------' . PHP_EOL); } - fwrite($fp, PHP_EOL . PHP_EOL. PHP_EOL); + fwrite($fp, PHP_EOL . PHP_EOL . PHP_EOL); fclose($fp); + + return true; + } + + function writeErrorMessages() + { + $filename = CONTENT_PATH . 'queries.log'; + + if( !file_exists($filename) || !is_writable($filename) ) { + return false; + } + + $fp = fopen($filename, 'a'); + + if( $fp == false ) { + return false; + } + + foreach($this->messages as $msg) { + if( $msg['errno'] > 0 ) { + fwrite($fp, '--------------------------------------------------' . PHP_EOL); + fwrite($fp, 'QUERY TIME' . ' ' . $msg['query_time'] . PHP_EOL); + fwrite($fp, 'Error number: ' . $msg['errno'] . PHP_EOL); + fwrite($fp, 'Error description: ' . $msg['error'] . PHP_EOL); + fwrite($fp, '**************************************************' . PHP_EOL); + fwrite($fp, $msg['query'] . PHP_EOL); + fwrite($fp, '--------------------------------------------------' . PHP_EOL); + fwrite($fp, PHP_EOL . PHP_EOL); + } + } + + fclose($fp); + return true; } @@ -239,6 +272,3 @@ public function getTotalNumberQueries() return count($this->messages); } } - - /* file end: ./oc-includes/osclass/Logger/LogDatabase.php */ -?> diff --git a/oc-includes/osclass/classes/database/DBConnectionClass.php b/oc-includes/osclass/classes/database/DBConnectionClass.php index 6dce34c586..161239f9c3 100755 --- a/oc-includes/osclass/classes/database/DBConnectionClass.php +++ b/oc-includes/osclass/classes/database/DBConnectionClass.php @@ -118,13 +118,13 @@ class DBConnectionClass /** A list of incompatible SQL modes. - * - * @since @TODO <----- - * @access protected - * @var array - */ - protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', - 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); + * + * @since @TODO <----- + * @access protected + * @var array + */ + protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', + 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); /** * It creates a new DBConnection object class or if it has been created before, it @@ -276,7 +276,7 @@ function connectToOsclassDb() if ( $conn == false ) { $this->errorConnection(); $this->releaseOsclassDb(); - + if(MULTISITE) { return false; } @@ -498,15 +498,15 @@ public function set_sql_mode($modes = array(), &$connId) $modes = array_change_key_case( $modes, CASE_UPPER ); $incompatible_modes = $this->incompatible_modes; - foreach ( $modes as $i => $mode ) { - if ( in_array( $mode, $incompatible_modes ) ) { + foreach ( $modes as $i => $mode ) { + if ( in_array( $mode, $incompatible_modes ) ) { unset( $modes[ $i ] ); - } - } + } + } - $modes_str = implode( ',', $modes ); + $modes_str = implode( ',', $modes ); mysqli_query($connId, "SET SESSION sql_mode='$modes_str'" ); - } + } /** * At the end of the execution it prints the database debug if it's necessary @@ -530,7 +530,9 @@ function debug($printFrontend = true) return false; } - if( OSC_DEBUG_DB_LOG ) { + if( OSC_DEBUG_DB_LOG_ERROR ) { + $log->writeErrorMessages(); + } else if( OSC_DEBUG_DB_LOG ) { $log->writeMessages(); } else if($printFrontend) { $log->printMessages(); @@ -615,7 +617,4 @@ function _getDb(&$connId) return false; } - } - - /* file end: ./oc-includes/osclass/classes/database/DBConnectionClass.php */ -?> \ No newline at end of file + } diff --git a/oc-includes/osclass/default-constants.php b/oc-includes/osclass/default-constants.php index e6fa69404c..e43f50b38b 100755 --- a/oc-includes/osclass/default-constants.php +++ b/oc-includes/osclass/default-constants.php @@ -76,6 +76,10 @@ define('OSC_DEBUG_DB_LOG', false); } + if( !defined('OSC_DEBUG_DB_LOG_ERROR') ) { + define('OSC_DEBUG_DB_LOG_ERROR', false); + } + if( !defined('OSC_DEBUG_DB_EXPLAIN') ) { define('OSC_DEBUG_DB_EXPLAIN', false); }