5 # A Simple SQL Database Abstraction Object 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). 12 # Author: Edward Almasy (almasy@axisdata.com) 14 # Part of the AxisPHP library v1.2.5 15 # For more information see http://www.axisdata.com/AxisPHP/ 25 # ---- PUBLIC INTERFACE -------------------------------------------------- 42 $UserName = NULL, $Password = NULL, $DatabaseName = NULL, $HostName = NULL)
44 # save DB access parameter values 45 $this->
DBUserName = $UserName ? $UserName : self::$GlobalDBUserName;
46 $this->DBPassword = $Password ? $Password : self::$GlobalDBPassword;
48 (isset(self::$GlobalDBHostName) ? self::$GlobalDBHostName
50 $this->
DBName = $DatabaseName ? $DatabaseName : self::$GlobalDBName;
52 # set memory threshold for cache clearing 53 if (!isset(self::$CacheMemoryThreshold))
55 self::$CacheMemoryThreshold = self::GetPhpMemoryLimit() / 4;
58 # if we don't already have a connection or DB access parameters were supplied 60 if (!array_key_exists($HandleIndex, self::$ConnectionHandles)
61 || $UserName || $Password || $DatabaseName || $HostName)
63 # open connection to DB server 64 self::$ConnectionHandles[$HandleIndex] = mysqli_connect(
67 or die(
"Could not connect to database: ".mysqli_connect_error());
69 # set local connection handle 70 $this->Handle = self::$ConnectionHandles[$HandleIndex];
73 mysqli_select_db($this->Handle, $this->
DBName)
74 or die(mysqli_error($this->Handle));
78 # set local connection handle 79 $this->Handle = self::$ConnectionHandles[$HandleIndex];
89 return array(
"DBUserName",
"DBPassword",
"DBHostName",
"DBName");
96 # open connection to DB server 97 $this->Handle = mysqli_connect(
99 or die(
"could not connect to database");
102 mysqli_select_db($this->Handle, $this->
DBName)
103 or die(mysqli_error($this->Handle));
115 $UserName, $Password, $HostName =
"localhost")
117 # save default DB access parameters 118 self::$GlobalDBUserName = $UserName;
119 self::$GlobalDBPassword = $Password;
120 self::$GlobalDBHostName = $HostName;
122 # clear any existing DB connection handles 123 self::$ConnectionHandles = array();
132 # save new default DB name 133 self::$GlobalDBName = $DatabaseName;
135 # clear any existing DB connection handles 136 self::$ConnectionHandles = array();
145 # choose config variable to use based on server version number 147 ?
"storage_engine" :
"default_storage_engine";
149 # set storage engine in database 150 $this->
Query(
"SET ".$ConfigVar.
" = ".$Engine);
161 # retrieve version string 162 $Version = $this->
Query(
"SELECT VERSION() AS ServerVer",
"ServerVer");
166 # strip off any build/config suffix 167 $Pieces = explode(
"-", $Version);
168 $Version = array_shift($Pieces);
171 # return version number to caller 185 return mysqli_get_client_info();
195 return mysqli_get_host_info($this->Handle);
235 public static function Caching($NewSetting = NULL)
237 # if cache setting has changed 238 if (($NewSetting !== NULL) && ($NewSetting != self::$CachingFlag))
241 self::$CachingFlag = $NewSetting;
243 # clear any existing cached results 244 self::$QueryResultCache = array();
247 # return current setting to caller 248 return self::$CachingFlag;
263 if ($NewSetting !== NULL)
265 self::$AdvancedCachingFlag = $NewSetting;
267 return self::$AdvancedCachingFlag;
291 if ($NormalizeWhitespace && ($ErrorsToIgnore !== NULL))
293 $RevisedErrorsToIgnore = array();
294 foreach ($ErrorsToIgnore as $SqlPattern => $ErrMsgPattern)
296 $SqlPattern = preg_replace(
"/\\s+/",
"\\s+", $SqlPattern);
297 $RevisedErrorsToIgnore[$SqlPattern] = $ErrMsgPattern;
299 $ErrorsToIgnore = $RevisedErrorsToIgnore;
301 $this->ErrorsToIgnore = $ErrorsToIgnore;
311 return $this->ErrorIgnored;
327 public function Query($QueryString, $FieldName =
"")
329 # clear flag that indicates whether query error was ignored 330 $this->ErrorIgnored = FALSE;
332 # if caching is enabled 333 if (self::$CachingFlag)
335 # if SQL statement is read-only 336 if ($this->IsReadOnlyStatement($QueryString))
338 # if we have statement in cache 339 if (isset(self::$QueryResultCache[$QueryString][
"NumRows"]))
341 if (self::$QueryDebugOutputFlag)
342 { print(
"DB-C: $QueryString<br>\n"); }
344 # make sure query result looks okay 345 $this->QueryHandle = TRUE;
347 # increment cache hit counter 348 self::$CachedQueryCounter++;
350 # make local copy of results 351 $this->QueryResults = self::$QueryResultCache[$QueryString];
352 $this->NumRows = self::$QueryResultCache[$QueryString][
"NumRows"];
354 # set flag to indicate that results should be retrieved from cache 355 $this->GetResultsFromCache = TRUE;
359 # execute SQL statement 360 $this->QueryHandle = $this->RunQuery($QueryString);
361 if (!$this->QueryHandle instanceof mysqli_result) {
return FALSE; }
363 # save number of rows in result 364 $this->NumRows = mysqli_num_rows($this->QueryHandle);
366 # if too many rows to cache 367 if ($this->NumRows >= self::$CacheRowsThreshold)
369 # set flag to indicate that query results should not 370 # be retrieved from cache 371 $this->GetResultsFromCache = FALSE;
375 # if we are low on memory 376 if (self::GetFreeMemory() < self::$CacheMemoryThreshold)
378 # clear out all but last few rows from cache 379 self::$QueryResultCache = array_slice(
380 self::$QueryResultCache,
381 (0 - self::$CacheRowsToLeave));
384 # if advanced caching is enabled 385 if (self::$AdvancedCachingFlag)
387 # save tables accessed by query 388 self::$QueryResultCache[$QueryString][
"TablesAccessed"] =
389 $this->TablesAccessed($QueryString);
393 if ($this->NumRows > 0)
396 for ($Row = 0; $Row < $this->NumRows; $Row++)
398 $this->QueryResults[$Row] =
399 mysqli_fetch_assoc($this->QueryHandle);
402 # cache query results 403 self::$QueryResultCache[$QueryString] = $this->QueryResults;
407 # clear local query results 408 unset($this->QueryResults);
411 # cache number of rows 412 self::$QueryResultCache[$QueryString][
"NumRows"] = $this->NumRows;
414 # set flag to indicate that query results should be 415 # retrieved from cache 416 $this->GetResultsFromCache = TRUE;
422 # if advanced caching is enabled 423 if (self::$AdvancedCachingFlag)
425 # if table modified by statement is known 426 $TableModified = $this->TableModified($QueryString);
429 # for each cached query 430 foreach (self::$QueryResultCache
431 as $CachedQueryString => $CachedQueryResult)
433 # if we know what tables were accessed 434 if ($CachedQueryResult[
"TablesAccessed"])
436 # if tables accessed include the one we may modify 437 if (in_array($TableModified,
438 $CachedQueryResult[
"TablesAccessed"]))
440 # clear cached query results 441 unset($GLOBALS[
"APDBQueryResultCache"][$CachedQueryString]);
446 # clear cached query results 447 unset($GLOBALS[
"APDBQueryResultCache"][$CachedQueryString]);
453 # clear entire query result cache 454 self::$QueryResultCache = array();
459 # clear entire query result cache 460 self::$QueryResultCache = array();
463 # execute SQL statement 464 $this->QueryHandle = $this->RunQuery($QueryString);
465 if ($this->QueryHandle === FALSE) {
return FALSE; }
467 # set flag to indicate that query results should not be 468 # retrieved from cache 469 $this->GetResultsFromCache = FALSE;
473 $this->RowCounter = 0;
475 # increment query counter 476 self::$QueryCounter++;
480 # execute SQL statement 481 $this->QueryHandle = $this->RunQuery($QueryString);
482 if ($this->QueryHandle === FALSE) {
return FALSE; }
485 if (($FieldName !=
"") && ($this->QueryHandle != FALSE))
491 return $this->QueryHandle;
510 $FHandle = fopen($FileName,
"r");
512 # if file open succeeded 513 if ($FHandle !== FALSE)
515 # while lines left in file 518 while (!feof($FHandle))
520 # read in line from file 521 $Line = fgets($FHandle, 32767);
523 # trim whitespace from line 526 # if line is not empty and not a comment 527 if (!preg_match(
"/^#/", $Line)
528 && !preg_match(
"/^--/", $Line)
531 # add line to current query 534 # if line completes a query 535 if (preg_match(
"/;$/", $Line))
539 $Result = $this->
Query($Query);
542 # if query resulted in an error that is not ignorable 543 if ($Result === FALSE)
545 # stop processing queries and set error code 557 # return number of executed queries to caller 568 return $this->ErrMsg;
589 if ($NewValue !== NULL) { self::$DisplayErrors = $NewValue; }
590 return self::$DisplayErrors;
599 # if caching is enabled and query was cached 600 if (self::$CachingFlag && $this->GetResultsFromCache)
602 # return cached number of rows to caller 603 return $this->NumRows;
607 # call to this method after an unsuccessful query 608 if (!$this->QueryHandle instanceof mysqli_result)
613 # retrieve number of rows and return to caller 614 return mysqli_num_rows($this->QueryHandle);
625 # call to this method after an unsuccessful query 626 if (!$this->QueryHandle instanceof mysqli_result)
631 # retrieve number of rows and return to caller 632 return mysqli_affected_rows($this->Handle);
642 # if caching is enabled and query was cached 643 if (self::$CachingFlag && $this->GetResultsFromCache)
645 # if rows left to return 646 if ($this->RowCounter < $this->NumRows)
648 # retrieve row from cache 649 $Result = $this->QueryResults[$this->RowCounter];
651 # increment row counter 662 # call to this method after successful query 663 if ($this->QueryHandle instanceof mysqli_result)
665 $Result = mysqli_fetch_assoc($this->QueryHandle);
666 if ($Result === NULL) { $Result = FALSE; }
669 # call to this method after unsuccessful query 676 # return row to caller 688 # assume no rows will be returned 691 # for each available row 693 while ((($RowsFetched < $NumberOfRows) || ($NumberOfRows == NULL))
701 # return array of rows to caller 726 if ($IndexFieldName != NULL)
728 $Array[$Record[$IndexFieldName]] = $Record[$FieldName];
732 $Array[] = $Record[$FieldName];
749 return isset($Record[$FieldName]) ? $Record[$FieldName] : NULL;
760 return (
int)$this->
Query(
761 "SELECT LAST_INSERT_ID() AS InsertId",
780 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
782 # expand condition if supplied 783 if ($Condition != NULL) { $Condition =
" WHERE ".$Condition; }
785 # read cached record from database if not already loaded 786 if (!isset($CachedRecord))
788 $this->
Query(
"SELECT * FROM `".$TableName.
"` ".$Condition);
792 # if new value supplied 795 # update value in database 796 $this->
Query(
"UPDATE `".$TableName.
"` SET `".$FieldName.
"` = " 797 .(($NewValue === NULL) ?
"NULL" :
"'" 798 .mysqli_real_escape_string($this->Handle, $NewValue).
"'")
801 # update value in cached record 802 $CachedRecord[$FieldName] = $NewValue;
805 # return value from cached record to caller 806 return isset($CachedRecord[$FieldName])
807 ? $CachedRecord[$FieldName] : NULL;
827 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
831 $Condition, $CachedRecord);
851 $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
855 $Condition, $CachedRecord);
871 return mysqli_real_escape_string($this->Handle, $String);
882 $this->
Query(
"-- ".$String);
892 $this->
Query(
"SHOW TABLES LIKE '".addslashes($TableName).
"'");
904 $this->
Query(
"DESC ".$TableName);
905 while ($CurrentFieldName = $this->
FetchField(
"Field"))
907 if ($CurrentFieldName == $FieldName) {
return TRUE; }
920 $this->
Query(
"DESC ".$TableName);
922 return $AllTypes[$FieldName];
932 self::$QueryDebugOutputFlag = $NewSetting;
942 return self::$QueryCounter;
953 return self::$CachedQueryCounter;
963 if (self::$QueryCounter)
965 return (self::$CachedQueryCounter / self::$QueryCounter) * 100;
975 # ---- PRIVATE INTERFACE ------------------------------------------------- 983 private $QueryHandle;
984 private $QueryResults;
987 private $GetResultsFromCache;
988 private $ErrorIgnored = FALSE;
989 private $ErrorsToIgnore = NULL;
990 private $ErrMsg = NULL;
991 private $ErrNo = NULL;
993 private static $DisplayErrors = FALSE;
995 private static $GlobalDBUserName;
996 private static $GlobalDBPassword;
997 private static $GlobalDBHostName;
998 private static $GlobalDBName;
1001 private static $QueryDebugOutputFlag = FALSE;
1002 # flag for whether caching is turned on 1003 private static $CachingFlag = TRUE;
1004 # query result advanced caching flag 1005 private static $AdvancedCachingFlag = FALSE;
1006 # global cache for query results 1007 private static $QueryResultCache = array();
1009 private static $QueryCounter = 0;
1010 private static $CachedQueryCounter = 0;
1011 # database connection link handles 1012 private static $ConnectionHandles = array();
1013 # do not cache queries that return more than this number of rows 1014 private static $CacheRowsThreshold = 250;
1015 # prune the query cache if there is less than this amount of memory free 1016 private static $CacheMemoryThreshold;
1017 # number of rows to leave in cache when pruning 1018 private static $CacheRowsToLeave = 10;
1025 private function IsReadOnlyStatement($QueryString)
1027 return preg_match(
"/^[ ]*SELECT /i", $QueryString) ? TRUE : FALSE;
1036 private function TableModified($QueryString)
1038 # assume we're not going to be able to determine table 1041 # split query into pieces 1042 $QueryString = trim($QueryString);
1043 $Words = preg_split(
"/\s+/", $QueryString);
1045 # if INSERT statement 1047 if (strtoupper($Words[0]) ==
"INSERT")
1049 # skip over modifying keywords 1050 while ((strtoupper($Words[$WordIndex]) ==
"LOW_PRIORITY")
1051 || (strtoupper($Words[$WordIndex]) ==
"DELAYED")
1052 || (strtoupper($Words[$WordIndex]) ==
"IGNORE")
1053 || (strtoupper($Words[$WordIndex]) ==
"INTO"))
1058 # next word is table name 1059 $TableName = $Words[$WordIndex];
1061 # else if UPDATE statement 1062 elseif (strtoupper($Words[0]) ==
"UPDATE")
1064 # skip over modifying keywords 1065 while ((strtoupper($Words[$WordIndex]) ==
"LOW_PRIORITY")
1066 || (strtoupper($Words[$WordIndex]) ==
"IGNORE"))
1071 # if word following next word is SET 1072 if (strtoupper($Words[$WordIndex + 1]) ==
"SET")
1074 # next word is table name 1075 $TableName = $Words[$WordIndex];
1078 # else if DELETE statement 1079 elseif (strtoupper($Words[0]) ==
"DELETE")
1081 # skip over modifying keywords 1082 while ((strtoupper($Words[$WordIndex]) ==
"LOW_PRIORITY")
1083 || (strtoupper($Words[$WordIndex]) ==
"IGNORE")
1084 || (strtoupper($Words[$WordIndex]) ==
"QUICK"))
1089 # if next term is FROM 1090 if (strtoupper($Words[$WordIndex]) ==
"FROM")
1092 # next word is table name 1094 $TableName = $Words[$WordIndex];
1098 # discard table name if it looks at all suspicious 1101 if (!preg_match(
"/[a-zA-Z0-9]+/", $TableName))
1107 # return table name (or lack thereof) to caller 1117 private function TablesAccessed($QueryString)
1119 # assume we're not going to be able to determine tables 1120 $TableNames = FALSE;
1122 # split query into pieces 1123 $QueryString = trim($QueryString);
1124 $Words = preg_split(
"/\s+/", $QueryString);
1125 $UQueryString = strtoupper($QueryString);
1126 $UWords = preg_split(
"/\s+/", $UQueryString);
1128 # if SELECT statement 1129 if ($UWords[0] ==
"SELECT")
1131 # keep going until we hit FROM or last word 1133 while (($UWords[$WordIndex] !=
"FROM")
1134 && strlen($UWords[$WordIndex]))
1140 if ($UWords[$WordIndex] ==
"FROM")
1142 # for each word after FROM 1144 while (strlen($UWords[$WordIndex]))
1146 # if current word ends with comma 1147 if (preg_match(
"/,$/", $Words[$WordIndex]))
1149 # strip off comma and add word to table name list 1150 $TableNames[] = substr($Words[$WordIndex], 0, -1);
1154 # add word to table name list 1155 $TableNames[] = $Words[$WordIndex];
1157 # if next word is not comma 1159 if ($Words[$WordIndex] !=
",")
1161 # if word begins with comma 1162 if (preg_match(
"/^,/", $Words[$WordIndex]))
1164 # strip off comma (NOTE: modifies $Words array!) 1165 $Words[$WordIndex] = substr($Words[$WordIndex], 1);
1167 # decrement index so we start with this word next pass 1172 # stop scanning words (non-basic JOINs not yet handled) 1184 # discard table names if they look at all suspicious 1187 foreach ($TableNames as $Name)
1189 if (!preg_match(
"/^[a-zA-Z0-9]+$/", $Name))
1191 $TableNames = FALSE;
1197 # return table name (or lack thereof) to caller 1207 private function RunQuery($QueryString)
1209 # log query start time if debugging output is enabled 1210 if (self::$QueryDebugOutputFlag) { $QueryStartTime = microtime(TRUE); }
1212 # run query against database 1213 $this->QueryHandle = mysqli_query($this->Handle, $QueryString) ;
1215 # print query and execution time if debugging output is enabled 1216 if (self::$QueryDebugOutputFlag)
1218 print
"DB: ".$QueryString.
" [" 1219 .sprintf(
"%.2f", microtime(TRUE) - $QueryStartTime)
1223 # if query failed and there are errors that we can ignore 1224 if (($this->QueryHandle === FALSE) && $this->ErrorsToIgnore)
1226 # for each pattern for an error that we can ignore 1227 foreach ($this->ErrorsToIgnore as $SqlPattern => $ErrMsgPattern)
1229 # if error matches pattern 1230 $ErrorMsg = mysqli_error($this->Handle);
1231 if (preg_match($SqlPattern, $QueryString)
1232 && preg_match($ErrMsgPattern, $ErrorMsg))
1234 # set return value to indicate error was ignored 1235 $this->QueryHandle = TRUE;
1237 # set internal flag to indicate that an error was ignored 1238 $this->ErrorIgnored = $ErrorMsg;
1240 # stop looking at patterns 1247 if ($this->QueryHandle === FALSE)
1249 # clear stored value for number of rows retrieved 1252 # retrieve error info 1253 $this->ErrMsg = mysqli_error($this->Handle);
1254 $this->ErrNo = mysqli_errno($this->Handle);
1256 # if we are supposed to be displaying errors 1257 if (self::$DisplayErrors)
1260 print(
"<b>SQL Error:</b> <i>".$this->ErrMsg
1261 .
"</i> (".$this->ErrNo.
")<br/>\n");
1262 print(
"<b>SQL Statement:</b> <i>" 1263 .htmlspecialchars($QueryString).
"</i><br/>\n");
1265 # retrieve execution trace that got us to this point 1266 $Trace = debug_backtrace();
1268 # remove current context from trace 1269 array_shift($Trace);
1271 # make sure file name and line number are available 1272 foreach ($Trace as $Index => $Loc)
1274 if (!array_key_exists(
"file", $Loc))
1276 $Trace[$Index][
"file"] =
"UNKNOWN";
1278 if (!array_key_exists(
"line", $Loc))
1280 $Trace[$Index][
"line"] =
"??";
1284 # determine length of leading path common to all file names in trace 1286 $OurFile = __FILE__;
1288 foreach ($Trace as $Loc)
1290 if ($Loc[
"file"] !=
"UNKNOWN")
1293 $FNameLength = strlen($Loc[
"file"]);
1294 while ($Index < $FNameLength &&
1295 $Loc[
"file"][$Index] == $OurFile[$Index])
1297 $PrefixLen = min($PrefixLen, $Index);
1301 foreach ($Trace as $Loc)
1305 foreach ($Loc[
"args"] as $Arg)
1308 switch (gettype($Arg))
1311 $ArgString .= $Arg ?
"TRUE" :
"FALSE";
1320 $ArgString .=
'"<i>'.htmlspecialchars(substr($Arg, 0, 40))
1321 .((strlen($Arg) > 40) ?
"..." :
"").
'</i>"';
1327 $ArgString .= strtoupper(gettype($Arg));
1331 $ArgString .= get_class($Arg);
1334 case "unknown type":
1335 $ArgString .=
"UNKNOWN";
1340 $Loc[
"file"] = substr($Loc[
"file"], $PrefixLen);
1341 $LocString .=
" ";
1342 if (array_key_exists(
"class", $Loc))
1343 { $LocString .= $Loc[
"class"].
"::"; }
1344 $LocString .= $Loc[
"function"].
"(".$ArgString.
")" 1345 .
" - ".$Loc[
"file"].
":".$Loc[
"line"]
1348 print(
"<b>Trace:</b><br>\n".$LocString);
1351 return $this->QueryHandle;
1358 static private function GetPhpMemoryLimit()
1360 $Str = strtoupper(ini_get(
"memory_limit"));
1361 if (substr($Str, -1) ==
"B") { $Str = substr($Str, 0, strlen($Str) - 1); }
1362 switch (substr($Str, -1))
1364 case "K": $MemoryLimit = (int)$Str * 1024;
break;
1365 case "M": $MemoryLimit = (int)$Str * 1048576;
break;
1366 case "G": $MemoryLimit = (int)$Str * 1073741824;
break;
1367 default: $MemoryLimit = (int)$Str;
break;
1369 return $MemoryLimit;
1376 static private function GetFreeMemory()
1378 return self::GetPhpMemoryLimit() - memory_get_usage();
1382 # define return values (numerical values correspond to MySQL error codes) 1384 define(
"DB_OKAY", 0);
1385 define(
"DB_ERROR", 1);
1386 define(
"DB_ACCESSDENIED", 2);
1387 define(
"DB_UNKNOWNDB", 3);
1388 define(
"DB_UNKNOWNTABLE", 4);
1389 define(
"DB_SYNTAXERROR", 5);
1390 define(
"DB_DBALREADYEXISTS", 6);
1391 define(
"DB_DBDOESNOTEXIST", 7);
1392 define(
"DB_DISKFULL", 8);
1395 # define value to designate omitted arguments (so DB values can be set to NULL) 1396 define(
"DB_NOVALUE",
"!-_-_-DB_NOVALUE-_-_-!");
1398 # MySQL error code mapping 1409 # date() format for SQL dates 1410 define(
"DATE_SQL",
"Y-m-d H:i:s");
QueryErrMsg()
Get most recent error message text set by Query().
static Caching($NewSetting=NULL)
Get or set whether query result caching is currently enabled.
GetServerVersion($FullVersion=FALSE)
Get database server version number.
static SetGlobalDatabaseName($DatabaseName)
Set default database name.
SetDefaultStorageEngine($Engine)
Set default database storage engine.
ExecuteQueriesFromFile($FileName)
Execute queries from specified file.
UpdateIntValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set an integer value in the database.
SQL database abstraction object with smart query caching.
SetQueryErrorsToIgnore($ErrorsToIgnore, $NormalizeWhitespace=TRUE)
Set query errors to ignore.
DBUserName()
Get name used to connect with database server.
EscapeString($String)
Escape a string that may contain null bytes.
FetchRow()
Get next database row retrieved by most recent query.
LastInsertId()
Get ID of row added by the last SQL "INSERT" statement.
__construct($UserName=NULL, $Password=NULL, $DatabaseName=NULL, $HostName=NULL)
Object constructor.
TableExists($TableName)
Get whether specified table exists.
static SetGlobalServerInfo($UserName, $Password, $HostName="localhost")
GetClientVersion()
Get version number of the client libraries being used to connect to the database server (Currently th...
GetFieldType($TableName, $FieldName)
Get field (column) type.
NumRowsSelected()
Get number of rows returned by last SELECT or SHOW query.
FetchRows($NumberOfRows=NULL)
Get specified number of database rows retrieved by most recent query.
static QueryDebugOutput($NewSetting)
Enable or disable debugging output for queries.
Query($QueryString, $FieldName="")
Query database (with caching if enabled).
FetchField($FieldName)
Pull next row from last DB query and get a specific value from that row.
FieldExists($TableName, $FieldName)
Get whether specified field exists in specified table.
static NumCacheHits()
Get the number of queries that have resulted in cache hits since program execution began...
FetchColumn($FieldName, $IndexFieldName=NULL)
Get all available values for specified database field retrieved by most recent query.
DBHostName()
Get host name of system on which database server resides.
NumRowsAffected()
Get number of rows affected by last INSERT, UPDATE, REPLACE, or DELETE query.
UpdateFloatValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set a float value in the database.
QueryErrNo()
Get most recent error code set by Query().
GetHostInfo()
Get database connection type and hostname.
UpdateValue($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
A convenience function to get or set a value in the database.
static AdvancedCaching($NewSetting=NULL)
Get or set whether advanced query result cachine is currently enabled.
static DisplayQueryErrors($NewValue=NULL)
Get/set whether Query() errors will be displayed.
static CacheHitRate()
Get the ratio of query cache hits to queries as a percentage.
IgnoredError()
Check whether an error was ignored by the most recent query.
DBName()
Get current database name.
LogComment($String)
Peform query that consists of SQL comment statement.
__wakeup()
Restore database connection when unserialized.
static NumQueries()
Get the number of queries that have been run since program execution began.