CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Database.php
Go to the documentation of this file.
1 <?PHP
2
3 #
4 # Axis--Database.php
5 # A Simple SQL Database Abstraction Object
6 #
7 # Copyright 1999-2002 Axis Data
8 # This code is free software that can be used or redistributed under the
9 # terms of Version 2 of the GNU General Public License, as published by the
10 # Free Software Foundation (http://www.fsf.org).
11 #
12 # Author: Edward Almasy (almasy@axisdata.com)
13 #
14 # Part of the AxisPHP library v1.2.5
15 # For more information see http://www.axisdata.com/AxisPHP/
16 #
17
22 class Database
23 {
24
25 # ---- PUBLIC INTERFACE --------------------------------------------------
26 /*@(*/
28
43 public function __construct(
44 $UserName = NULL, $Password = NULL, $DatabaseName = NULL, $HostName = NULL)
45 {
46 # save DB access parameter values
47 $this->DBUserName = $UserName ? $UserName : self::$GlobalDBUserName;
48 $this->DBPassword = $Password ? $Password : self::$GlobalDBPassword;
49 $this->DBHostName = $HostName ? $HostName :
50 (isset(self::$GlobalDBHostName) ? self::$GlobalDBHostName
51 : "localhost");
52 $this->DBName = $DatabaseName ? $DatabaseName : self::$GlobalDBName;
53
54 # set memory threshold for cache clearing
55 if (!isset(self::$CacheMemoryThreshold))
56 {
57 self::$CacheMemoryThreshold = self::GetPhpMemoryLimit() / 4;
58 }
59
60 # if we don't already have a connection or DB access parameters were supplied
61 $HandleIndex = $this->DBHostName.":".$this->DBName;
62 if (!array_key_exists($HandleIndex, self::$ConnectionHandles)
63 || $UserName || $Password || $DatabaseName || $HostName)
64 {
65 # open connection to DB server and select database
66 $this->Handle = self::ConnectAndSelectDB($this->DBHostName,
67 $this->DBUserName, $this->DBPassword, $this->DBName);
68 self::$ConnectionHandles[$HandleIndex] = $this->Handle;
69 }
70 else
71 {
72 # set local connection handle
73 $this->Handle = self::$ConnectionHandles[$HandleIndex];
74 }
75 }
76
81 public function __sleep()
82 {
83 return array("DBUserName", "DBPassword", "DBHostName", "DBName");
84 }
90 public function __wakeup()
91 {
92 # if we don't already have a database server connection
93 $HandleIndex = $this->DBHostName.":".$this->DBName;
94 if (!array_key_exists($HandleIndex, self::$ConnectionHandles))
95 {
96 # open connection to DB server and select database
97 try
98 {
99 $this->Handle = self::ConnectAndSelectDB($this->DBHostName,
100 $this->DBUserName, $this->DBPassword, $this->DBName);
101 }
102 catch (Exception $Exception)
103 {
104 if (isset(self::$GlobalDBUserName)
105 && isset(self::$GlobalDBPassword)
106 && isset(self::$GlobalDBName))
107 {
108 $this->DBUserName = self::$GlobalDBUserName;
109 $this->DBPassword = self::$GlobalDBPassword;
110 $this->DBName = self::$GlobalDBName;
111 $this->DBHostName = isset(self::$GlobalDBHostName)
112 ? self::$GlobalDBHostName : "localhost";
113 $this->Handle = self::ConnectAndSelectDB($this->DBHostName,
114 $this->DBUserName, $this->DBPassword, $this->DBName);
115 }
116 else
117 {
118 throw $Exception;
119 }
120 }
121 self::$ConnectionHandles[$HandleIndex] = $this->Handle;
122 }
123 else
124 {
125 # set local connection handle
126 $this->Handle = self::$ConnectionHandles[$HandleIndex];
127 }
128 }
138 public static function SetGlobalServerInfo(
139 $UserName, $Password, $HostName = "localhost")
140 {
141 # save default DB access parameters
142 self::$GlobalDBUserName = $UserName;
143 self::$GlobalDBPassword = $Password;
144 self::$GlobalDBHostName = $HostName;
145
146 # clear any existing DB connection handles
147 self::$ConnectionHandles = array();
148 }
149
154 public static function SetGlobalDatabaseName($DatabaseName)
155 {
156 # save new default DB name
157 self::$GlobalDBName = $DatabaseName;
158
159 # clear any existing DB connection handles
160 self::$ConnectionHandles = array();
161 }
162
167 public function SetDefaultStorageEngine($Engine)
168 {
169 # choose config variable to use based on server version number
170 $ConfigVar = version_compare($this->GetServerVersion(), "5.5", "<")
171 ? "storage_engine" : "default_storage_engine";
172
173 # set storage engine in database
174 $this->Query("SET ".$ConfigVar." = ".$Engine);
175 }
176
183 public function GetServerVersion($FullVersion=FALSE)
184 {
185 # retrieve version string
186 $Version = $this->Query("SELECT VERSION() AS ServerVer", "ServerVer");
187
188 if (!$FullVersion)
189 {
190 # strip off any build/config suffix
191 $Pieces = explode("-", $Version);
192 $Version = array_shift($Pieces);
193 }
194
195 # return version number to caller
196 return $Version;
197 }
198
207 public function GetClientVersion()
208 {
209 return mysqli_get_client_info();
210 }
211
217 public function GetHostInfo()
218 {
219 return mysqli_get_host_info($this->Handle);
220 }
221
227 public function DBHostName()
228 {
229 return $this->DBHostName;
230 }
231
237 public function DBName()
238 {
239 return $this->DBName;
240 }
241
247 public function DBUserName()
248 {
249 return $this->DBUserName;
250 }
251
259 public static function Caching($NewSetting = NULL)
260 {
261 # if cache setting has changed
262 if (($NewSetting !== NULL) && ($NewSetting != self::$CachingFlag))
263 {
264 # save new setting
265 self::$CachingFlag = $NewSetting;
266
267 # clear any existing cached results
268 self::$QueryResultCache = array();
269 }
270
271 # return current setting to caller
272 return self::$CachingFlag;
273 }
274
285 public static function AdvancedCaching($NewSetting = NULL)
286 {
287 if ($NewSetting !== NULL)
288 {
289 self::$AdvancedCachingFlag = $NewSetting;
290 }
291 return self::$AdvancedCachingFlag;
292 }
293
313 public function SetQueryErrorsToIgnore($ErrorsToIgnore, $NormalizeWhitespace = TRUE)
314 {
315 if ($NormalizeWhitespace && ($ErrorsToIgnore !== NULL))
316 {
317 $RevisedErrorsToIgnore = array();
318 foreach ($ErrorsToIgnore as $SqlPattern => $ErrMsgPattern)
319 {
320 $SqlPattern = preg_replace("/\\s+/", "\\s+", $SqlPattern);
321 $RevisedErrorsToIgnore[$SqlPattern] = $ErrMsgPattern;
322 }
323 $ErrorsToIgnore = $RevisedErrorsToIgnore;
324 }
325 $this->ErrorsToIgnore = $ErrorsToIgnore;
326 }
327
333 public function IgnoredError()
334 {
335 return $this->ErrorIgnored;
336 }
337
338 /*@)*/ /* Setup/Initialization */ /*@(*/
340
351 public function Query($QueryString, $FieldName = "")
352 {
353 # clear flag that indicates whether query error was ignored
354 $this->ErrorIgnored = FALSE;
355
356 # if caching is enabled
357 if (self::$CachingFlag)
358 {
359 # if SQL statement is read-only
360 if ($this->IsReadOnlyStatement($QueryString))
361 {
362 # if we have statement in cache
363 if (isset(self::$QueryResultCache[$QueryString]["NumRows"]))
364 {
365 if (self::$QueryDebugOutputFlag)
366 { print("DB-C: $QueryString<br>\n"); }
367
368 # make sure query result looks okay
369 $this->QueryHandle = TRUE;
370
371 # increment cache hit counter
372 self::$CachedQueryCounter++;
373
374 # make local copy of results
375 $this->QueryResults = self::$QueryResultCache[$QueryString];
376 $this->NumRows = self::$QueryResultCache[$QueryString]["NumRows"];
377
378 # set flag to indicate that results should be retrieved from cache
379 $this->GetResultsFromCache = TRUE;
380 }
381 else
382 {
383 # execute SQL statement
384 $this->QueryHandle = $this->RunQuery($QueryString);
385 if (!$this->QueryHandle instanceof mysqli_result) { return FALSE; }
386
387 # save number of rows in result
388 $this->NumRows = mysqli_num_rows($this->QueryHandle);
389
390 # if too many rows to cache
391 if ($this->NumRows >= self::$CacheRowsThreshold)
392 {
393 # set flag to indicate that query results should not
394 # be retrieved from cache
395 $this->GetResultsFromCache = FALSE;
396 }
397 else
398 {
399 # if we are low on memory
400 if (self::GetFreeMemory() < self::$CacheMemoryThreshold)
401 {
402 # clear out all but last few rows from cache
403 self::$QueryResultCache = array_slice(
404 self::$QueryResultCache,
405 (0 - self::$CacheRowsToLeave));
406 }
407
408 # if advanced caching is enabled
409 if (self::$AdvancedCachingFlag)
410 {
411 # save tables accessed by query
412 self::$QueryResultCache[$QueryString]["TablesAccessed"] =
413 $this->TablesAccessed($QueryString);
414 }
415
416 # if rows found
417 if ($this->NumRows > 0)
418 {
419 # load query results
420 for ($Row = 0; $Row < $this->NumRows; $Row++)
421 {
422 $this->QueryResults[$Row] =
423 mysqli_fetch_assoc($this->QueryHandle);
424 }
425
426 # cache query results
427 self::$QueryResultCache[$QueryString] = $this->QueryResults;
428 }
429 else
430 {
431 # clear local query results
432 unset($this->QueryResults);
433 }
434
435 # cache number of rows
436 self::$QueryResultCache[$QueryString]["NumRows"] = $this->NumRows;
437
438 # set flag to indicate that query results should be
439 # retrieved from cache
440 $this->GetResultsFromCache = TRUE;
441 }
442 }
443 }
444 else
445 {
446 # if advanced caching is enabled
447 if (self::$AdvancedCachingFlag)
448 {
449 # if table modified by statement is known
450 $TableModified = $this->TableModified($QueryString);
451 if ($TableModified)
452 {
453 # for each cached query
454 foreach (self::$QueryResultCache
455 as $CachedQueryString => $CachedQueryResult)
456 {
457 # if we know what tables were accessed
458 if ($CachedQueryResult["TablesAccessed"])
459 {
460 # if tables accessed include the one we may modify
461 if (in_array($TableModified,
462 $CachedQueryResult["TablesAccessed"]))
463 {
464 # clear cached query results
465 unset(self::$QueryResultCache[$CachedQueryString]);
466 }
467 }
468 else
469 {
470 # clear cached query results
471 unset(self::$QueryResultCache[$CachedQueryString]);
472 }
473 }
474 }
475 else
476 {
477 # clear entire query result cache
478 self::$QueryResultCache = array();
479 }
480 }
481 else
482 {
483 # clear entire query result cache
484 self::$QueryResultCache = array();
485 }
486
487 # execute SQL statement
488 $this->QueryHandle = $this->RunQuery($QueryString);
489 if ($this->QueryHandle === FALSE) { return FALSE; }
490
491 # set flag to indicate that query results should not be
492 # retrieved from cache
493 $this->GetResultsFromCache = FALSE;
494 }
495
496 # reset row counter
497 $this->RowCounter = 0;
498
499 # increment query counter
500 self::$QueryCounter++;
501 }
502 else
503 {
504 # execute SQL statement
505 $this->QueryHandle = $this->RunQuery($QueryString);
506 if ($this->QueryHandle === FALSE) { return FALSE; }
507 }
508
509 if (($FieldName != "") && ($this->QueryHandle !== FALSE))
510 {
511 return $this->FetchField($FieldName);
512 }
513 else
514 {
515 return $this->QueryHandle;
516 }
517 }
518
531 public function ExecuteQueriesFromFile($FileName)
532 {
533 # open file
534 $FHandle = fopen($FileName, "r");
535
536 # if file open succeeded
537 if ($FHandle !== FALSE)
538 {
539 # while lines left in file
540 $Query = "";
541 $QueryCount = 0;
542 while (!feof($FHandle))
543 {
544 # read in line from file
545 $Line = fgets($FHandle, 32767);
546
547 # trim whitespace from line
548 $Line = trim($Line);
549
550 # if line is not empty and not a comment
551 if (!preg_match("/^#/", $Line)
552 && !preg_match("/^--/", $Line)
553 && strlen($Line))
554 {
555 # add line to current query
556 $Query .= " ".$Line;
557
558 # if line completes a query
559 if (preg_match("/;$/", $Line))
560 {
561 # run query
562 $QueryCount++;
563 $Result = $this->Query($Query);
564 $Query = "";
565
566 # if query resulted in an error that is not ignorable
567 if ($Result === FALSE)
568 {
569 # stop processing queries and set error code
570 $QueryCount = NULL;
571 break;
572 }
573 }
574 }
575 }
576
577 # close file
578 fclose($FHandle);
579 }
580
581 # return number of executed queries to caller
582 return $QueryCount;
583 }
584
590 public function QueryErrMsg()
591 {
592 return $this->ErrMsg;
593 }
594
600 public function QueryErrNo()
601 {
602 return $this->ErrNo;
603 }
604
611 public static function DisplayQueryErrors($NewValue = NULL)
612 {
613 if ($NewValue !== NULL) { self::$DisplayErrors = $NewValue; }
614 return self::$DisplayErrors;
615 }
616
621 public function NumRowsSelected()
622 {
623 # if caching is enabled and query was cached
624 if (self::$CachingFlag && $this->GetResultsFromCache)
625 {
626 # return cached number of rows to caller
627 return $this->NumRows;
628 }
629 else
630 {
631 # call to this method after an unsuccessful query
632 if (!$this->QueryHandle instanceof mysqli_result)
633 {
634 return 0;
635 }
636
637 # retrieve number of rows and return to caller
638 return mysqli_num_rows($this->QueryHandle);
639 }
640 }
641
647 public function NumRowsAffected()
648 {
649 # call to this method after an unsuccessful query
650 if ($this->QueryHandle === FALSE)
651 {
652 return 0;
653 }
654
655 # retrieve number of rows and return to caller
656 return mysqli_affected_rows($this->Handle);
657 }
658
664 public function FetchRow()
665 {
666 # if caching is enabled and query was cached
667 if (self::$CachingFlag && $this->GetResultsFromCache)
668 {
669 # if rows left to return
670 if ($this->RowCounter < $this->NumRows)
671 {
672 # retrieve row from cache
673 $Result = $this->QueryResults[$this->RowCounter];
674
675 # increment row counter
676 $this->RowCounter++;
677 }
678 else
679 {
680 # return nothing
681 $Result = FALSE;
682 }
683 }
684 else
685 {
686 # call to this method after successful query
687 if ($this->QueryHandle instanceof mysqli_result)
688 {
689 $Result = mysqli_fetch_assoc($this->QueryHandle);
690 if ($Result === NULL) { $Result = FALSE; }
691 }
692
693 # call to this method after unsuccessful query
694 else
695 {
696 $Result = FALSE;
697 }
698 }
699
700 # return row to caller
701 return $Result;
702 }
703
710 public function FetchRows($NumberOfRows = NULL)
711 {
712 # assume no rows will be returned
713 $Result = array();
714
715 # for each available row
716 $RowsFetched = 0;
717 while ((($RowsFetched < $NumberOfRows) || ($NumberOfRows == NULL))
718 && ($Row = $this->FetchRow()))
719 {
720 # add row to results
721 $Result[] = $Row;
722 $RowsFetched++;
723 }
724
725 # return array of rows to caller
726 return $Result;
727 }
728
745 public function FetchColumn($FieldName, $IndexFieldName = NULL)
746 {
747 $Array = array();
748 while ($Record = $this->FetchRow())
749 {
750 if ($IndexFieldName != NULL)
751 {
752 $Array[$Record[$IndexFieldName]] = $Record[$FieldName];
753 }
754 else
755 {
756 $Array[] = $Record[$FieldName];
757 }
758 }
759 return $Array;
760 }
761
770 public function FetchField($FieldName)
771 {
772 $Record = $this->FetchRow();
773 return isset($Record[$FieldName]) ? $Record[$FieldName] : NULL;
774 }
775
782 public function LastInsertId()
783 {
784 return (int)$this->Query(
785 "SELECT LAST_INSERT_ID() AS InsertId",
786 "InsertId");
787 }
788
803 public function UpdateValue(
804 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
805 {
806 # expand condition if supplied
807 if ($Condition != NULL) { $Condition = " WHERE ".$Condition; }
808
809 # if cached values not already loaded
810 if (!isset($CachedRecord))
811 {
812 # read cached record from database
813 $this->Query("SELECT * FROM `".$TableName."` ".$Condition);
814 $CachedRecord = $this->FetchRow();
815
816 # error out if requested column does not exist in specified table
817 if ($NewValue === DB_NOVALUE)
818 {
819 $RowsFound = ($this->NumRowsSelected() > 0);
820 if (($RowsFound && !array_key_exists($FieldName, $CachedRecord))
821 || (!$RowsFound && !$this->FieldExists($TableName, $FieldName)))
822 {
823 throw new Exception("Column '".$FieldName
824 ."' not found in table '".$TableName."'.");
825 }
826 }
827 }
828
829 # if new value supplied
830 if ($NewValue !== DB_NOVALUE)
831 {
832 # error out if we are trying to update a nonexistent record or field
833 if (!count($CachedRecord))
834 {
835 throw new Exception("No records found when attempting to update"
836 ." column '".$FieldName."' in table '".$TableName."'"
837 .(($Condition != NULL)
838 ? " using condition '".$Condition."'" : "")
839 .".");
840 }
841 else
842 {
843 if (!array_key_exists($FieldName, $CachedRecord))
844 {
845 throw new Exception("Attempting to update column '".$FieldName
846 ."', which does not exist in table '".$TableName."'.");
847 }
848 }
849
850 # update value in database
851 $this->Query("UPDATE `".$TableName."` SET `".$FieldName."` = "
852 .(($NewValue === NULL) ? "NULL" : "'"
853 .mysqli_real_escape_string($this->Handle, $NewValue)."'")
854 .$Condition);
855
856 # update value in cached record
857 $CachedRecord[$FieldName] = $NewValue;
858 }
859
860 # return value from cached record to caller
861 return isset($CachedRecord[$FieldName])
862 ? $CachedRecord[$FieldName] : NULL;
863 }
864
881 public function UpdateIntValue(
882 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
883 {
884 return $this->UpdateValue($TableName, $FieldName,
885 (($NewValue === DB_NOVALUE) ? DB_NOVALUE : (int)$NewValue),
886 $Condition, $CachedRecord);
887 }
888
905 public function UpdateFloatValue(
906 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
907 {
908 return $this->UpdateValue($TableName, $FieldName,
909 (($NewValue === DB_NOVALUE) ? DB_NOVALUE : (float)$NewValue),
910 $Condition, $CachedRecord);
911 }
912
924 public function CopyValues($TableName, $IdColumn, $SrcId, $DstId,
925 $ColumnsToExclude = array())
926 {
927 # retrieve names of all columns in table
928 $AllColumns = $this->GetColumns($TableName);
929
930 # remove columns to be excluded from copy
931 $ColumnsToExclude[] = $IdColumn;
932 $ColumnsToCopy = array_diff($AllColumns, $ColumnsToExclude);
933
934 # normalize destination IDs
935 $DstIds = is_array($DstId) ? $DstId : array($DstId);
936 $DstIds = array_diff($DstIds, array($SrcId));
937
938 # if there are columns to copy and we have destinations
939 if (count($ColumnsToCopy) && count($DstIds))
940 {
941 # construct and execute query to perform copy
942 $Query = "UPDATE `".$TableName."` AS Target"
943 ." LEFT JOIN `".$TableName."` AS Source"
944 ." ON Source.`".$IdColumn."` = '".addslashes($SrcId)."'";
945 $QuerySets = array();
946 foreach ($ColumnsToCopy as $ColumnName)
947 {
948 $QuerySets[] = "Target.`".$ColumnName."` = Source.`".$ColumnName."`";
949 }
950 $Query .= " SET ".implode(", ", $QuerySets);
951 $QueryConditions = array();
952 foreach ($DstIds as $Id)
953 {
954 $QueryConditions[] = "Target.`".$IdColumn."` = '".addslashes($DstId)."'";
955 }
956 $Query .= " WHERE ".implode(" OR ", $QueryConditions);
957 $this->Query($Query);
958 }
959 }
960
974 public function InsertArray($Table, $ValueField, $Values,
975 $KeyField = NULL, $AvgDataLength = 20)
976 {
977 # pick some ballpark values
978 $ChunkSizeAssumedSafe = 100;
979 $QueryLengthAssumedSafe = 10486576; # (1 MB)
980
981 # exit without doing anything if there are no values
982 $ValueCount = count($Values);
983 if ($ValueCount == 0)
984 {
985 return;
986 }
987
988 # determine size of array chunk per INSERT statement
989 $NonValueCharCount = 100;
990 if ($ValueCount > $ChunkSizeAssumedSafe)
991 {
992 $MaxQueryLen = $this->GetMaxQueryLength();
993 $ValueSegmentLen = $AvgDataLength + 6;
994 if ($KeyField !== NULL)
995 {
996 $ValueSegmentLen = $ValueSegmentLen * 2;
997 }
998 $ValueChunkSize = $MaxQueryLen / $ValueSegmentLen;
999 }
1000 else
1001 {
1002 $ValueChunkSize = $ChunkSizeAssumedSafe;
1003 }
1004
1005 # for each chunk of values
1006 foreach (array_chunk($Values, $ValueChunkSize, TRUE) as $ValueChunk)
1007 {
1008 # begin building query
1009 $Query = "INSERT INTO `".$Table."` (`".$ValueField."`";
1010
1011 # if key field was specified
1012 if ($KeyField !== NULL)
1013 {
1014 # add key field to query
1015 $Query .= ", `".$KeyField."`";
1016
1017 # assemble value segment with keys
1018 $ValueSegFunc = function($Carry, $Key) use ($ValueChunk)
1019 {
1020 $Carry .= "('".addslashes($ValueChunk[$Key])."','"
1021 .addslashes($Key)."'),";
1022 return $Carry;
1023 };
1024 $ValueSegment = array_reduce(array_keys($ValueChunk), $ValueSegFunc);
1025 }
1026 else
1027 {
1028 # assemble value segment
1029 $ValueSegFunc = function($Carry, $Value)
1030 {
1031 $Carry .= "('".addslashes($Value)."'),";
1032 return $Carry;
1033 };
1034 $ValueSegment = array_reduce($ValueChunk, $ValueSegFunc);
1035 }
1036
1037 # trim extraneous comma off of value segment
1038 $ValueSegment = substr($ValueSegment, 0, -1);
1039
1040 # add value segment to query
1041 $Query .= ") VALUES ".$ValueSegment;
1042
1043 # double check to make sure query isn't too long
1044 $QueryLen = strlen($Query);
1045 if ($QueryLen > $QueryLengthAssumedSafe)
1046 {
1047 if (!isset($MaxQueryLen))
1048 {
1049 $MaxQueryLen = $this->GetMaxQueryLength();
1050 }
1051 if ($QueryLen > $MaxQueryLen)
1052 {
1053 throw new Exception("Maximum query length ("
1054 .$MaxQueryLen.") exceeded (".$QueryLen.").");
1055 }
1056 }
1057
1058 # run query
1059 $this->Query($Query);
1060 }
1061 }
1062
1063 /*@)*/ /* Data Manipulation */ /*@(*/
1065
1074 public function EscapeString($String)
1075 {
1076 return mysqli_real_escape_string($this->Handle, $String);
1077 }
1078
1085 public function LogComment($String)
1086 {
1087 $this->Query("-- ".$String);
1088 }
1089
1095 public function TableExists($TableName)
1096 {
1097 $this->Query("SHOW TABLES LIKE '".addslashes($TableName)."'");
1098 return $this->NumRowsSelected() ? TRUE : FALSE;
1099 }
1100
1107 public function FieldExists($TableName, $FieldName)
1108 {
1109 $this->Query("DESC ".$TableName);
1110 while ($CurrentFieldName = $this->FetchField("Field"))
1111 {
1112 if ($CurrentFieldName == $FieldName) { return TRUE; }
1113 }
1114 return FALSE;
1115 }
1116
1123 public function GetFieldType($TableName, $FieldName)
1124 {
1125 $this->Query("DESC ".$TableName);
1126 $AllTypes = $this->FetchColumn("Type", "Field");
1127 return $AllTypes[$FieldName];
1128 }
1129
1135 public function GetColumns($TableName)
1136 {
1137 $this->Query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS"
1138 ." WHERE TABLE_SCHEMA = '".addslashes($this->DBName)
1139 ."' AND TABLE_NAME = '".addslashes($TableName)."'");
1140 return $this->FetchColumn("COLUMN_NAME");
1141 }
1142
1147 public function GetMaxQueryLength()
1148 {
1149 return $this->Query("SHOW VARIABLES LIKE 'max_allowed_packet'",
1150 "Value");
1151 }
1152
1158 public static function QueryDebugOutput($NewSetting)
1159 {
1160 self::$QueryDebugOutputFlag = $NewSetting;
1161 }
1162
1168 public static function NumQueries()
1169 {
1170 return self::$QueryCounter;
1171 }
1172
1179 public static function NumCacheHits()
1180 {
1181 return self::$CachedQueryCounter;
1182 }
1183
1189 public static function CacheHitRate()
1190 {
1191 if (self::$QueryCounter)
1192 {
1193 return (self::$CachedQueryCounter / self::$QueryCounter) * 100;
1194 }
1195 else
1196 {
1197 return 0;
1198 }
1199 }
1200
1201 /*@)*/ /* Miscellaneous */
1202
1203 # ---- PRIVATE INTERFACE -------------------------------------------------
1204
1205 protected $DBUserName;
1206 protected $DBPassword;
1207 protected $DBHostName;
1208 protected $DBName;
1209
1210 private $Handle;
1211 private $QueryHandle;
1212 private $QueryResults;
1213 private $RowCounter;
1214 private $NumRows;
1215 private $GetResultsFromCache;
1216 private $ErrorIgnored = FALSE;
1217 private $ErrorsToIgnore = NULL;
1218 private $ErrMsg = NULL;
1219 private $ErrNo = NULL;
1220
1221 private static $DisplayErrors = FALSE;
1222
1223 private static $GlobalDBUserName;
1224 private static $GlobalDBPassword;
1225 private static $GlobalDBHostName;
1226 private static $GlobalDBName;
1227
1228 # debug output flag
1229 private static $QueryDebugOutputFlag = FALSE;
1230 # flag for whether caching is turned on
1231 private static $CachingFlag = TRUE;
1232 # query result advanced caching flag
1233 private static $AdvancedCachingFlag = FALSE;
1234 # global cache for query results
1235 private static $QueryResultCache = array();
1236 # stats counters
1237 private static $QueryCounter = 0;
1238 private static $CachedQueryCounter = 0;
1239 # database connection link handles
1240 private static $ConnectionHandles = array();
1241 # do not cache queries that return more than this number of rows
1242 private static $CacheRowsThreshold = 250;
1243 # prune the query cache if there is less than this amount of memory free
1244 private static $CacheMemoryThreshold;
1245 # number of rows to leave in cache when pruning
1246 private static $CacheRowsToLeave = 10;
1247 # number of retry attempts to make to connect to database
1248 private static $ConnectRetryAttempts = 3;
1249 # number of seconds to wait between connection retry attempts
1250 private static $ConnectRetryInterval = 5;
1251
1252 # server connection error codes
1253 const CR_CONNECTION_ERROR = 2002; # Can't connect to local MySQL server
1254 # through socket '%s' (%d)
1255 const CR_CONN_HOST_ERROR = 2003; # Can't connect to MySQL server on '%s' (%d)
1256 const CR_SERVER_GONE_ERROR = 2006; # MySQL server has gone away
1257 const CR_SERVER_LOST = 2013; # Lost connection to MySQL server during query
1258
1259 # connection error codes that may be recoverable
1260 private static $RecoverableConnectionErrors = array(
1261 self::CR_CONNECTION_ERROR,
1262 );
1263
1274 private static function ConnectAndSelectDB(
1275 $DBHostName, $DBUserName, $DBPassword, $DBName)
1276 {
1277 $ConnectAttemptsLeft = self::$ConnectRetryAttempts + 1;
1278 do
1279 {
1280 # if this is not our first connection attempt
1281 if (isset($Handle))
1282 {
1283 # wait for the retry interval
1284 sleep(self::$ConnectRetryInterval);
1285 }
1286
1287 # attempt to connect to server
1288 $Handle = @mysqli_connect($DBHostName, $DBUserName, $DBPassword);
1289 $ConnectAttemptsLeft--;
1290 }
1291 # repeat if we do not have a connection and there are retry attempts
1292 # left and the connection error code indicates a retry may succeed
1293 // @codingStandardsIgnoreStart
1294 // (because phpcs apparently doesn't know how to handle do-while loops)
1295 while (!$Handle && $ConnectAttemptsLeft
1296 && in_array(mysqli_connect_errno(),
1297 self::$RecoverableConnectionErrors));
1298 // @codingStandardsIgnoreEnd
1299
1300 # throw exception if connection attempts failed
1301 if (!$Handle)
1302 {
1303 throw new Exception("Could not connect to database: "
1304 .mysqli_connect_error()." (errno: ".mysqli_connect_errno().")");
1305 }
1306
1307 # select DB
1308 $Result = mysqli_select_db($Handle, $DBName);
1309 if ($Result !== TRUE)
1310 {
1311 throw new Exception("Could not select database: "
1312 .mysqli_error($Handle)." (errno: ".mysqli_errno($Handle).")");
1313 }
1314
1315 # return new connection to caller
1316 return $Handle;
1317 }
1318
1324 private function IsReadOnlyStatement($QueryString)
1325 {
1326 return preg_match("/^[ ]*SELECT /i", $QueryString) ? TRUE : FALSE;
1327 }
1328
1335 private function TableModified($QueryString)
1336 {
1337 # assume we're not going to be able to determine table
1338 $TableName = FALSE;
1339
1340 # split query into pieces
1341 $QueryString = trim($QueryString);
1342 $Words = preg_split("/\s+/", $QueryString);
1343
1344 # if INSERT statement
1345 $WordIndex = 1;
1346 if (strtoupper($Words[0]) == "INSERT")
1347 {
1348 # skip over modifying keywords
1349 while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
1350 || (strtoupper($Words[$WordIndex]) == "DELAYED")
1351 || (strtoupper($Words[$WordIndex]) == "IGNORE")
1352 || (strtoupper($Words[$WordIndex]) == "INTO"))
1353 {
1354 $WordIndex++;
1355 }
1356
1357 # next word is table name
1358 $TableName = $Words[$WordIndex];
1359 }
1360 # else if UPDATE statement
1361 elseif (strtoupper($Words[0]) == "UPDATE")
1362 {
1363 # skip over modifying keywords
1364 while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
1365 || (strtoupper($Words[$WordIndex]) == "IGNORE"))
1366 {
1367 $WordIndex++;
1368 }
1369
1370 # if word following next word is SET
1371 if (strtoupper($Words[$WordIndex + 1]) == "SET")
1372 {
1373 # next word is table name
1374 $TableName = $Words[$WordIndex];
1375 }
1376 }
1377 # else if DELETE statement
1378 elseif (strtoupper($Words[0]) == "DELETE")
1379 {
1380 # skip over modifying keywords
1381 while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
1382 || (strtoupper($Words[$WordIndex]) == "IGNORE")
1383 || (strtoupper($Words[$WordIndex]) == "QUICK"))
1384 {
1385 $WordIndex++;
1386 }
1387
1388 # if next term is FROM
1389 if (strtoupper($Words[$WordIndex]) == "FROM")
1390 {
1391 # next word is table name
1392 $WordIndex++;
1393 $TableName = $Words[$WordIndex];
1394 }
1395 }
1396
1397 # discard table name if it looks at all suspicious
1398 if ($TableName)
1399 {
1400 if (!preg_match("/[a-zA-Z0-9]+/", $TableName))
1401 {
1402 $TableName = FALSE;
1403 }
1404 }
1405
1406 # return table name (or lack thereof) to caller
1407 return $TableName;
1408 }
1409
1416 private function TablesAccessed($QueryString)
1417 {
1418 # assume we're not going to be able to determine tables
1419 $TableNames = FALSE;
1420
1421 # split query into pieces
1422 $QueryString = trim($QueryString);
1423 $Words = preg_split("/\s+/", $QueryString);
1424 $UQueryString = strtoupper($QueryString);
1425 $UWords = preg_split("/\s+/", $UQueryString);
1426
1427 # if SELECT statement
1428 if ($UWords[0] == "SELECT")
1429 {
1430 # keep going until we hit FROM or last word
1431 $WordIndex = 1;
1432 while (($UWords[$WordIndex] != "FROM")
1433 && strlen($UWords[$WordIndex]))
1434 {
1435 $WordIndex++;
1436 }
1437
1438 # if we hit FROM
1439 if ($UWords[$WordIndex] == "FROM")
1440 {
1441 # for each word after FROM
1442 $WordIndex++;
1443 while (strlen($UWords[$WordIndex]))
1444 {
1445 # if current word ends with comma
1446 if (preg_match("/,$/", $Words[$WordIndex]))
1447 {
1448 # strip off comma and add word to table name list
1449 $TableNames[] = substr($Words[$WordIndex], 0, -1);
1450 }
1451 else
1452 {
1453 # add word to table name list
1454 $TableNames[] = $Words[$WordIndex];
1455
1456 # if next word is not comma
1457 $WordIndex++;
1458 if ($Words[$WordIndex] != ",")
1459 {
1460 # if word begins with comma
1461 if (preg_match("/^,/", $Words[$WordIndex]))
1462 {
1463 # strip off comma (NOTE: modifies $Words array!)
1464 $Words[$WordIndex] = substr($Words[$WordIndex], 1);
1465
1466 # decrement index so we start with this word next pass
1467 $WordIndex--;
1468 }
1469 else
1470 {
1471 # stop scanning words (non-basic JOINs not yet handled)
1472 break;
1473 }
1474 }
1475 }
1476
1477 # move to next word
1478 $WordIndex++;
1479 }
1480 }
1481 }
1482
1483 # discard table names if they look at all suspicious
1484 if ($TableNames)
1485 {
1486 foreach ($TableNames as $Name)
1487 {
1488 if (!preg_match("/^[a-zA-Z0-9]+$/", $Name))
1489 {
1490 $TableNames = FALSE;
1491 break;
1492 }
1493 }
1494 }
1495
1496 # return table name (or lack thereof) to caller
1497 return $TableNames;
1498 }
1499
1506 private function RunQuery($QueryString)
1507 {
1508 # log query start time if debugging output is enabled
1509 if (self::$QueryDebugOutputFlag) { $QueryStartTime = microtime(TRUE); }
1510
1511 # run query against database
1512 $this->QueryHandle = mysqli_query($this->Handle, $QueryString) ;
1513
1514 # print query and execution time if debugging output is enabled
1515 if (self::$QueryDebugOutputFlag)
1516 {
1517 print "DB: ".$QueryString." ["
1518 .sprintf("%.2f", microtime(TRUE) - $QueryStartTime)
1519 ."s]"."<br>\n";
1520 }
1521
1522 # if query failed and there are errors that we can ignore
1523 if (($this->QueryHandle === FALSE) && $this->ErrorsToIgnore)
1524 {
1525 # for each pattern for an error that we can ignore
1526 foreach ($this->ErrorsToIgnore as $SqlPattern => $ErrMsgPattern)
1527 {
1528 # if error matches pattern
1529 $ErrorMsg = mysqli_error($this->Handle);
1530 if (preg_match($SqlPattern, $QueryString)
1531 && preg_match($ErrMsgPattern, $ErrorMsg))
1532 {
1533 # set return value to indicate error was ignored
1534 $this->QueryHandle = TRUE;
1535
1536 # set internal flag to indicate that an error was ignored
1537 $this->ErrorIgnored = $ErrorMsg;
1538
1539 # stop looking at patterns
1540 break;
1541 }
1542 }
1543 }
1544
1545 # if query failed
1546 if ($this->QueryHandle === FALSE)
1547 {
1548 # clear stored value for number of rows retrieved
1549 $this->NumRows = 0;
1550
1551 # retrieve error info
1552 $this->ErrMsg = mysqli_error($this->Handle);
1553 $this->ErrNo = mysqli_errno($this->Handle);
1554
1555 # if we are supposed to be displaying errors
1556 if (self::$DisplayErrors)
1557 {
1558 # print error info
1559 print("<b>SQL Error:</b> <i>".$this->ErrMsg
1560 ."</i> (".$this->ErrNo.")<br/>\n");
1561 print("<b>SQL Statement:</b> <i>"
1562 .htmlspecialchars($QueryString)."</i><br/>\n");
1563
1564 # retrieve execution trace that got us to this point
1565 $Trace = debug_backtrace();
1566
1567 # remove current context from trace
1568 array_shift($Trace);
1569
1570 # make sure file name and line number are available
1571 foreach ($Trace as $Index => $Loc)
1572 {
1573 if (!array_key_exists("file", $Loc))
1574 {
1575 $Trace[$Index]["file"] = "UNKNOWN";
1576 }
1577 if (!array_key_exists("line", $Loc))
1578 {
1579 $Trace[$Index]["line"] = "??";
1580 }
1581 }
1582
1583 # determine length of leading path common to all file names in trace
1584 $LocString = "";
1585 $OurFile = __FILE__;
1586 $PrefixLen = 9999;
1587 foreach ($Trace as $Loc)
1588 {
1589 if ($Loc["file"] != "UNKNOWN")
1590 {
1591 $Index = 0;
1592 $FNameLength = strlen($Loc["file"]);
1593 while ($Index < $FNameLength &&
1594 $Loc["file"][$Index] == $OurFile[$Index])
1595 { $Index++; }
1596 $PrefixLen = min($PrefixLen, $Index);
1597 }
1598 }
1599
1600 foreach ($Trace as $Loc)
1601 {
1602 $Sep = "";
1603 $ArgString = "";
1604 foreach ($Loc["args"] as $Arg)
1605 {
1606 $ArgString .= $Sep;
1607 switch (gettype($Arg))
1608 {
1609 case "boolean":
1610 $ArgString .= $Arg ? "TRUE" : "FALSE";
1611 break;
1612
1613 case "integer":
1614 case "double":
1615 $ArgString .= $Arg;
1616 break;
1617
1618 case "string":
1619 $ArgString .= '"<i>'.htmlspecialchars(substr($Arg, 0, 40))
1620 .((strlen($Arg) > 40) ? "..." : "").'</i>"';
1621 break;
1622
1623 case "array":
1624 case "resource":
1625 case "NULL":
1626 $ArgString .= strtoupper(gettype($Arg));
1627 break;
1628
1629 case "object":
1630 $ArgString .= get_class($Arg);
1631 break;
1632
1633 case "unknown type":
1634 $ArgString .= "UNKNOWN";
1635 break;
1636 }
1637 $Sep = ",";
1638 }
1639 $Loc["file"] = substr($Loc["file"], $PrefixLen);
1640 $LocString .= "&nbsp;&nbsp;";
1641 if (array_key_exists("class", $Loc))
1642 { $LocString .= $Loc["class"]."::"; }
1643 $LocString .= $Loc["function"]."(".$ArgString.")"
1644 ." - ".$Loc["file"].":".$Loc["line"]
1645 ."<br>\n";
1646 }
1647 print("<b>Trace:</b><br>\n".$LocString);
1648 }
1649 }
1650 return $this->QueryHandle;
1651 }
1652
1657 static private function GetPhpMemoryLimit()
1658 {
1659 $Str = strtoupper(ini_get("memory_limit"));
1660 if (substr($Str, -1) == "B") { $Str = substr($Str, 0, strlen($Str) - 1); }
1661 switch (substr($Str, -1))
1662 {
1663 case "K":
1664 $MemoryLimit = (int)$Str * 1024;
1665 break;
1666
1667 case "M":
1668 $MemoryLimit = (int)$Str * 1048576;
1669 break;
1670
1671 case "G":
1672 $MemoryLimit = (int)$Str * 1073741824;
1673 break;
1674
1675 default:
1676 $MemoryLimit = (int)$Str;
1677 break;
1678 }
1679 return $MemoryLimit;
1680 }
1681
1686 static private function GetFreeMemory()
1687 {
1688 return self::GetPhpMemoryLimit() - memory_get_usage();
1689 }
1690 }
1691
1692 # define return values (numerical values correspond to MySQL error codes)
1693 // @codingStandardsIgnoreStart (to silence warning about multiple spaces)
1694 define("DB_OKAY", 0);
1695 define("DB_ERROR", 1);
1696 define("DB_ACCESSDENIED", 2);
1697 define("DB_UNKNOWNDB", 3);
1698 define("DB_UNKNOWNTABLE", 4);
1699 define("DB_SYNTAXERROR", 5);
1700 define("DB_DBALREADYEXISTS", 6);
1701 define("DB_DBDOESNOTEXIST", 7);
1702 define("DB_DISKFULL", 8);
1703 // @codingStandardsIgnoreEnd
1704
1705 # define value to designate omitted arguments (so DB values can be set to NULL)
1706 define("DB_NOVALUE", "!-_-_-DB_NOVALUE-_-_-!");
1707
1708 # MySQL error code mapping
1709 $APDBErrorCodeMappings = array(
1710 1045 => DB_ACCESSDENIED,
1711 1049 => DB_UNKNOWNDB,
1712 1046 => DB_UNKNOWNTABLE,
1713 1064 => DB_SYNTAXERROR,
1714 1007 => DB_DBALREADYEXISTS, # ? (not sure)
1715 1008 => DB_DBDOESNOTEXIST, # ? (not sure)
1716 1021 => DB_DISKFULL, # ? (not sure)
1717 );
1718
1719 # date() format for SQL dates
1720 define("DATE_SQL", "Y-m-d H:i:s");
Database\QueryErrMsg
QueryErrMsg()
Get most recent error message text set by Query().
Definition: Database.php:590
Database\$DBName
$DBName
Definition: Database.php:1208
Database\Caching
static Caching($NewSetting=NULL)
Get or set whether query result caching is currently enabled.
Definition: Database.php:259
Database\__sleep
__sleep()
Definition: Database.php:81
Database\GetServerVersion
GetServerVersion($FullVersion=FALSE)
Get database server version number.
Definition: Database.php:183
Database\SetGlobalDatabaseName
static SetGlobalDatabaseName($DatabaseName)
Set default database name.
Definition: Database.php:154
Database\CR_CONNECTION_ERROR
const CR_CONNECTION_ERROR
Definition: Database.php:1253
DB_ACCESSDENIED
const DB_ACCESSDENIED
Definition: Database.php:1696
Database\SetDefaultStorageEngine
SetDefaultStorageEngine($Engine)
Set default database storage engine.
Definition: Database.php:167
Database\ExecuteQueriesFromFile
ExecuteQueriesFromFile($FileName)
Execute queries from specified file.
Definition: Database.php:531
Database\$DBPassword
$DBPassword
Definition: Database.php:1206
Database\$DBUserName
$DBUserName
Definition: Database.php:1205
Database\UpdateIntValue
UpdateIntValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set an integer value in the database.
Definition: Database.php:881
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Database\SetQueryErrorsToIgnore
SetQueryErrorsToIgnore($ErrorsToIgnore, $NormalizeWhitespace=TRUE)
Set query errors to ignore.
Definition: Database.php:313
Database\CR_SERVER_GONE_ERROR
const CR_SERVER_GONE_ERROR
Definition: Database.php:1256
Database\DBUserName
DBUserName()
Get name used to connect with database server.
Definition: Database.php:247
Database\EscapeString
EscapeString($String)
Escape a string that may contain null bytes.
Definition: Database.php:1074
Database\FetchRow
FetchRow()
Get next database row retrieved by most recent query.
Definition: Database.php:664
Database\LastInsertId
LastInsertId()
Get ID of row added by the last SQL "INSERT" statement.
Definition: Database.php:782
Database\CR_SERVER_LOST
const CR_SERVER_LOST
Definition: Database.php:1257
DB_SYNTAXERROR
const DB_SYNTAXERROR
Definition: Database.php:1699
Database\__construct
__construct($UserName=NULL, $Password=NULL, $DatabaseName=NULL, $HostName=NULL)
Object constructor.
Definition: Database.php:43
Database\TableExists
TableExists($TableName)
Get whether specified table exists.
Definition: Database.php:1095
DB_DISKFULL
const DB_DISKFULL
Definition: Database.php:1702
Database\SetGlobalServerInfo
static SetGlobalServerInfo($UserName, $Password, $HostName="localhost")
Set default login and host info for database server.
Definition: Database.php:138
$APDBErrorCodeMappings
$APDBErrorCodeMappings
Definition: Database.php:1709
Database\$DBHostName
$DBHostName
Definition: Database.php:1207
PHP
PHP
Definition: RSSClient--Test.php:12
Database\GetClientVersion
GetClientVersion()
Get version number of the client libraries being used to connect to the database server (Currently th...
Definition: Database.php:207
Database\GetFieldType
GetFieldType($TableName, $FieldName)
Get field (column) type.
Definition: Database.php:1123
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1706
Database\NumRowsSelected
NumRowsSelected()
Get number of rows returned by last SELECT or SHOW query.
Definition: Database.php:621
Database\FetchRows
FetchRows($NumberOfRows=NULL)
Get specified number of database rows retrieved by most recent query.
Definition: Database.php:710
Database\QueryDebugOutput
static QueryDebugOutput($NewSetting)
Enable or disable debugging output for queries.
Definition: Database.php:1158
Database\Query
Query($QueryString, $FieldName="")
Query database (with caching if enabled).
Definition: Database.php:351
Database\GetColumns
GetColumns($TableName)
Get column (database field) names.
Definition: Database.php:1135
Database\FetchField
FetchField($FieldName)
Pull next row from last DB query and get a specific value from that row.
Definition: Database.php:770
Database\FieldExists
FieldExists($TableName, $FieldName)
Get whether specified field exists in specified table.
Definition: Database.php:1107
Database\NumCacheHits
static NumCacheHits()
Get the number of queries that have resulted in cache hits since program execution began...
Definition: Database.php:1179
DB_UNKNOWNTABLE
const DB_UNKNOWNTABLE
Definition: Database.php:1698
Database\FetchColumn
FetchColumn($FieldName, $IndexFieldName=NULL)
Get all available values for specified database field retrieved by most recent query.
Definition: Database.php:745
Database\DBHostName
DBHostName()
Get host name of system on which database server resides.
Definition: Database.php:227
DB_DBDOESNOTEXIST
const DB_DBDOESNOTEXIST
Definition: Database.php:1701
Database\NumRowsAffected
NumRowsAffected()
Get number of rows affected by last INSERT, UPDATE, REPLACE, or DELETE query.
Definition: Database.php:647
Database\UpdateFloatValue
UpdateFloatValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set a float value in the database.
Definition: Database.php:905
DB_DBALREADYEXISTS
const DB_DBALREADYEXISTS
Definition: Database.php:1700
Database\InsertArray
InsertArray($Table, $ValueField, $Values, $KeyField=NULL, $AvgDataLength=20)
Insert an array of values with a minimum number of INSERT statements.
Definition: Database.php:974
Database\QueryErrNo
QueryErrNo()
Get most recent error code set by Query().
Definition: Database.php:600
DB_UNKNOWNDB
const DB_UNKNOWNDB
Definition: Database.php:1697
Database\GetHostInfo
GetHostInfo()
Get database connection type and hostname.
Definition: Database.php:217
Database\UpdateValue
UpdateValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set a value in the database.
Definition: Database.php:803
Database\AdvancedCaching
static AdvancedCaching($NewSetting=NULL)
Get or set whether advanced query result cachine is currently enabled.
Definition: Database.php:285
Database\DisplayQueryErrors
static DisplayQueryErrors($NewValue=NULL)
Get/set whether Query() errors will be displayed.
Definition: Database.php:611
Database\CacheHitRate
static CacheHitRate()
Get the ratio of query cache hits to queries as a percentage.
Definition: Database.php:1189
Database\GetMaxQueryLength
GetMaxQueryLength()
Get maximum size for query string.
Definition: Database.php:1147
Database\IgnoredError
IgnoredError()
Check whether an error was ignored by the most recent query.
Definition: Database.php:333
Database\DBName
DBName()
Get current database name.
Definition: Database.php:237
Database\CopyValues
CopyValues($TableName, $IdColumn, $SrcId, $DstId, $ColumnsToExclude=array())
A convenience function to copy values from one row to another.
Definition: Database.php:924
Database\LogComment
LogComment($String)
Peform query that consists of SQL comment statement.
Definition: Database.php:1085
Database\__wakeup
__wakeup()
Restore database connection when unserialized.
Definition: Database.php:90
Database\NumQueries
static NumQueries()
Get the number of queries that have been run since program execution began.
Definition: Database.php:1168