Changeset 56 for trunk/Packages/Common/Database.php
- Timestamp:
- Apr 7, 2020, 9:13:33 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Database.php
r55 r56 2 2 3 3 // Extended database class 4 // Date: 2016-01-11 4 // Date: 2020-04-07 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 ();88 $this->LastQuery = $Query; 94 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float(); 95 $this->LastQuery = $Query; 89 96 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 90 $Duration = ' ; '.round(microtime () - $QueryStartTime, 4). ' s';97 $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s'; 91 98 if ($this->LogSQLQuery == true) 92 99 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); … … 101 108 $this->insert_id = $this->PDO->lastInsertId(); 102 109 } else 103 { 110 { 104 111 $this->Error = $this->PDO->errorInfo(); 105 112 $this->Error = $this->Error[2]; … … 123 130 function insert($Table, $Data) 124 131 { 132 $this->query($this->GetInsert($Table, $Data)); 133 $this->insert_id = $this->PDO->lastInsertId(); 134 } 135 136 function GetInsert($Table, $Data) 137 { 125 138 $Name = ''; 126 139 $Values = ''; … … 137 150 $Name = substr($Name, 1); 138 151 $Values = substr($Values, 1); 139 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 140 $this->insert_id = $this->PDO->lastInsertId(); 152 return 'INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'; 141 153 } 142 154 143 155 function update($Table, $Condition, $Data) 156 { 157 $this->query($this->GetUpdate($Table, $Condition, $Data)); 158 } 159 160 function GetUpdate($Table, $Condition, $Data) 144 161 { 145 162 $Values = ''; … … 154 171 } 155 172 $Values = substr($Values, 2); 156 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');173 return 'UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'; 157 174 } 158 175 … … 200 217 public function __wakeup() 201 218 { 219 } 220 221 public function Transaction($Queries) 222 { 223 $this->PDO->beginTransaction(); 224 foreach ($Queries as $Query) 225 { 226 $Statement = $this->PDO->prepare($Query); 227 $Statement->execute(); 228 } 229 $this->PDO->commit(); 202 230 } 203 231 }
Note:
See TracChangeset
for help on using the changeset viewer.