Changeset 873 for trunk/Packages/Common/Database.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Database.php
r861 r873 17 17 function fetch_assoc() 18 18 { 19 return ($this->PDOStatement->fetch(PDO::FETCH_ASSOC));19 return ($this->PDOStatement->fetch(PDO::FETCH_ASSOC)); 20 20 } 21 21 22 22 function fetch_array() 23 23 { 24 return ($this->PDOStatement->fetch(PDO::FETCH_BOTH));24 return ($this->PDOStatement->fetch(PDO::FETCH_BOTH)); 25 25 } 26 26 27 27 function fetch_row() 28 28 { 29 return ($this->PDOStatement->fetch(PDO::FETCH_NUM));29 return ($this->PDOStatement->fetch(PDO::FETCH_NUM)); 30 30 } 31 31 } … … 61 61 function Connect($Host, $User, $Password, $Database) 62 62 { 63 if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;64 else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;63 if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 64 else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; 65 65 else $ConnectionString = ''; 66 66 try { … … 81 81 function Connected() 82 82 { 83 return (isset($this->PDO));83 return (isset($this->PDO)); 84 84 } 85 85 … … 91 91 function query($Query) 92 92 { 93 if (!$this->Connected()) throw new Exception(T('Not connected to database'));94 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();93 if (!$this->Connected()) throw new Exception(T('Not connected to database')); 94 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float(); 95 95 $this->LastQuery = $Query; 96 96 //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float()); 97 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))97 if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 98 98 { 99 99 $Time = round(microtime_float() - $QueryStartTime, 4); 100 100 $Duration = ' ; '.$Time. ' s'; 101 101 } 102 if (($this->LogSQLQuery == true) and ($Time != 0))102 if (($this->LogSQLQuery == true) and ($Time != 0)) 103 103 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); 104 if ($this->ShowSQLQuery == true)104 if ($this->ShowSQLQuery == true) 105 105 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '. 106 106 'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n"); 107 107 $Result = new DatabaseResult(); 108 108 $Result->PDOStatement = $this->PDO->query($Query); 109 if ($Result->PDOStatement)109 if ($Result->PDOStatement) 110 110 { 111 111 $Result->num_rows = $Result->PDOStatement->rowCount(); … … 115 115 $this->Error = $this->PDO->errorInfo(); 116 116 $this->Error = $this->Error[2]; 117 if (($this->Error != '') and ($this->ShowSQLError == true))117 if (($this->Error != '') and ($this->ShowSQLError == true)) 118 118 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 119 119 throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query); 120 120 } 121 return ($Result);121 return ($Result); 122 122 } 123 123 124 124 function select($Table, $What = '*', $Condition = 1) 125 125 { 126 return ($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));126 return ($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 127 127 } 128 128 … … 142 142 $Name = ''; 143 143 $Values = ''; 144 foreach ($Data as $Key => $Value)144 foreach ($Data as $Key => $Value) 145 145 { 146 146 $Name .= ',`'.$Key.'`'; 147 if (!in_array($Value, $this->Functions))147 if (!in_array($Value, $this->Functions)) 148 148 { 149 if (is_null($Value)) $Value = 'NULL';149 if (is_null($Value)) $Value = 'NULL'; 150 150 else $Value = $this->PDO->quote($Value); 151 151 } … … 154 154 $Name = substr($Name, 1); 155 155 $Values = substr($Values, 1); 156 return ('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');156 return ('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 157 157 } 158 158 … … 165 165 { 166 166 $Values = ''; 167 foreach ($Data as $Key => $Value)168 { 169 if (!in_array($Value, $this->Functions))167 foreach ($Data as $Key => $Value) 168 { 169 if (!in_array($Value, $this->Functions)) 170 170 { 171 if (is_null($Value)) $Value = 'NULL';171 if (is_null($Value)) $Value = 'NULL'; 172 172 else $Value = $this->PDO->quote($Value); 173 173 } … … 175 175 } 176 176 $Values = substr($Values, 2); 177 return ('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');177 return ('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 178 178 } 179 179 … … 182 182 $Name = ''; 183 183 $Values = ''; 184 foreach ($Data as $Key => $Value)185 { 186 if (!in_array($Value, $this->Functions))184 foreach ($Data as $Key => $Value) 185 { 186 if (!in_array($Value, $this->Functions)) 187 187 { 188 if (is_null($Value)) $Value = 'NULL';188 if (is_null($Value)) $Value = 'NULL'; 189 189 else $Value = $this->PDO->quote($Value); 190 190 } … … 206 206 function real_escape_string($Text) 207 207 { 208 return (addslashes($Text));208 return (addslashes($Text)); 209 209 } 210 210 211 211 function quote($Text) 212 212 { 213 return ($this->PDO->quote($Text));213 return ($this->PDO->quote($Text)); 214 214 } 215 215 … … 239 239 function TimeToMysqlDateTime($Time) 240 240 { 241 if ($Time == NULL) return(NULL);242 else return (date('Y-m-d H:i:s', $Time));241 if ($Time == NULL) return (NULL); 242 else return (date('Y-m-d H:i:s', $Time)); 243 243 } 244 244 245 245 function TimeToMysqlDate($Time) 246 246 { 247 if ($Time == NULL) return(NULL);248 else return (date('Y-m-d', $Time));247 if ($Time == NULL) return (NULL); 248 else return (date('Y-m-d', $Time)); 249 249 } 250 250 251 251 function TimeToMysqlTime($Time) 252 252 { 253 if ($Time == NULL) return(NULL);254 else return (date('H:i:s', $Time));253 if ($Time == NULL) return (NULL); 254 else return (date('H:i:s', $Time)); 255 255 } 256 256 257 257 function MysqlDateTimeToTime($DateTime) 258 258 { 259 if ($DateTime == '') return(NULL);259 if ($DateTime == '') return (NULL); 260 260 $Parts = explode(' ', $DateTime); 261 261 $DateParts = explode('-', $Parts[0]); 262 262 $TimeParts = explode(':', $Parts[1]); 263 263 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 264 return ($Result);264 return ($Result); 265 265 } 266 266 267 267 function MysqlDateToTime($Date) 268 268 { 269 if ($Date == '') return(NULL);270 return (MysqlDateTimeToTime($Date.' 0:0:0'));269 if ($Date == '') return (NULL); 270 return (MysqlDateTimeToTime($Date.' 0:0:0')); 271 271 } 272 272 273 273 function MysqlTimeToTime($Time) 274 274 { 275 if ($Time == '') return(NULL);276 return (MysqlDateTimeToTime('0000-00-00 '.$Time));277 } 275 if ($Time == '') return (NULL); 276 return (MysqlDateTimeToTime('0000-00-00 '.$Time)); 277 }
Note:
See TracChangeset
for help on using the changeset viewer.