Ignore:
Timestamp:
Oct 25, 2017, 10:55:05 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Use better transaction mechanism for netwatch import and latency measurement.
  • Fixed: Query duration mesurement using outdated microtime result.
File:
1 edited

Legend:

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

    r851 r852  
    33// Extended database class
    44// Date: 2016-01-11
     5
     6function microtime_float()
     7{
     8  list($usec, $sec) = explode(" ", microtime());
     9  return ((float)$usec + (float)$sec);
     10}
    511
    612class DatabaseResult
     
    5157    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    5258  }
     59 
    5360
    5461  function Connect($Host, $User, $Password, $Database)
     
    8592  {
    8693    if(!$this->Connected()) throw new Exception(T('Not connected to database'));
    87     if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime();
     94    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
    8895    $this->LastQuery = $Query;
     96    //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float());
    8997    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    90       $Duration = ' ; '.round(microtime() - $QueryStartTime, 4). ' s';
     98      $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s';
    9199    if($this->LogSQLQuery == true)
    92100      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
     
    123131  function insert($Table, $Data)
    124132  {
     133    $this->query($this->GetInsert($Table, $Data));
     134    $this->insert_id = $this->PDO->lastInsertId();
     135  }
     136 
     137  function GetInsert($Table, $Data)
     138  {
    125139    $Name = '';
    126140    $Values = '';
     
    137151    $Name = substr($Name, 1);
    138152    $Values = substr($Values, 1);
    139     $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    140     $this->insert_id = $this->PDO->lastInsertId();
     153    return('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    141154  }
    142155
    143156  function update($Table, $Condition, $Data)
     157  {
     158    $this->query($this->GetUpdate($Table, $Condition, $Data));
     159  }
     160 
     161  function GetUpdate($Table, $Condition, $Data)
    144162  {
    145163    $Values = '';
     
    154172    }
    155173    $Values = substr($Values, 2);
    156     //echo('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
    157     $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
     174    return('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
    158175  }
    159176
Note: See TracChangeset for help on using the changeset viewer.