Changeset 9 for Common/Database.php
- Timestamp:
- Apr 7, 2020, 8:50:42 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/Database.php
r8 r9 3 3 // Extended database class 4 4 // Date: 2016-01-11 5 6 function microtime_float() 7 { 8 list($usec, $sec) = explode(" ", microtime()); 9 return ((float)$usec + (float)$sec); 10 } 5 11 6 12 class DatabaseResult … … 51 57 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 52 58 } 59 53 60 54 61 function Connect($Host, $User, $Password, $Database) … … 85 92 { 86 93 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(); 88 95 $this->LastQuery = $Query; 96 //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float()); 89 97 if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 90 $Duration = ' ; '.round(microtime () - $QueryStartTime, 4). ' s';98 $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s'; 91 99 if($this->LogSQLQuery == true) 92 100 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); … … 101 109 $this->insert_id = $this->PDO->lastInsertId(); 102 110 } else 103 { 111 { 104 112 $this->Error = $this->PDO->errorInfo(); 105 113 $this->Error = $this->Error[2]; … … 123 131 function insert($Table, $Data) 124 132 { 133 $this->query($this->GetInsert($Table, $Data)); 134 $this->insert_id = $this->PDO->lastInsertId(); 135 } 136 137 function GetInsert($Table, $Data) 138 { 125 139 $Name = ''; 126 140 $Values = ''; … … 137 151 $Name = substr($Name, 1); 138 152 $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.')'); 141 154 } 142 155 143 156 function update($Table, $Condition, $Data) 157 { 158 $this->query($this->GetUpdate($Table, $Condition, $Data)); 159 } 160 161 function GetUpdate($Table, $Condition, $Data) 144 162 { 145 163 $Values = ''; … … 154 172 } 155 173 $Values = substr($Values, 2); 156 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');174 return('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 157 175 } 158 176 … … 200 218 public function __wakeup() 201 219 { 220 } 221 222 public function Transaction($Queries) 223 { 224 $this->PDO->beginTransaction(); 225 foreach ($Queries as $Query) 226 { 227 $Statement = $this->PDO->prepare($Query); 228 $Statement->execute(); 229 } 230 $this->PDO->commit(); 202 231 } 203 232 }
Note:
See TracChangeset
for help on using the changeset viewer.