Ignore:
Timestamp:
Feb 28, 2016, 10:54:30 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Use object oriented approach for page drawing using Application class.
  • Added: SQL updated will be automatic using UpdateTrace.php file.
  • Added: Use generic setup page at URL /setup for SQL structure update.
  • Modified: Update Common package to newer version.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Database.php

    r55 r69  
    22
    33// Extended database class
    4 // Date: 2011-11-25
     4// Date: 2016-01-11
    55
    66class DatabaseResult
     
    2727class Database
    2828{
    29   var $Prefix = '';
     29  var $Prefix;
    3030  var $Functions;
    3131  var $Type;
    3232  var $PDO;
    33   var $Error = '';
     33  var $Error;
    3434  var $insert_id;
    35   var $LastQuery = '';
     35  var $LastQuery;
    3636  var $ShowSQLError;
    3737  var $ShowSQLQuery;
     38  var $LogSQLQuery;
     39  var $LogFile;
    3840
    3941  function __construct()
    4042  {
     43    $this->Prefix = '';
     44    $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
    4145    $this->Type = 'mysql';  // mysql, pgsql
     46    $this->Error = '';
     47    $this->LastQuery = '';
    4248    $this->ShowSQLError = false;
    4349    $this->ShowSQLQuery = false;
    44     $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
     50    $this->LogSQLQuery = false;
     51    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    4552  }
    4653
     
    7784  function query($Query)
    7885  {
    79     if(!$this->Connected()) throw new Exception('Not connected to database');
     86    if(!$this->Connected()) throw new Exception(T('Not connected to database'));
     87    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime();
    8088    $this->LastQuery = $Query;
     89    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
     90      $Duration = ' ; '.round(microtime() - $QueryStartTime, 4). ' s';
     91    if($this->LogSQLQuery == true)
     92      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    8193    if($this->ShowSQLQuery == true)
    82       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n");
     94      echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
     95      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    8396    $Result = new DatabaseResult();
    8497    $Result->PDOStatement = $this->PDO->query($Query);
     
    175188  }
    176189
     190  function quote($Text)
     191  {
     192    return($this->PDO->quote($Text));
     193  }
     194
    177195  public function __sleep()
    178196  {
Note: See TracChangeset for help on using the changeset viewer.