CWIS Developer Documentation
Axis--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  # ---- PUBLIC INTERFACE --------------------------------------------------
25  /*@(*/
27 
40  function Database(
41  $UserName = NULL, $Password = NULL, $DatabaseName = NULL, $HostName = NULL)
42  {
43  # save DB access parameter values
44  $this->DBUserName = $UserName ? $UserName : self::$GlobalDBUserName;
45  $this->DBPassword = $Password ? $Password : self::$GlobalDBPassword;
46  $this->DBHostName = $HostName ? $HostName :
47  (isset(self::$GlobalDBHostName) ? self::$GlobalDBHostName
48  : "localhost");
49  $this->DBName = $DatabaseName ? $DatabaseName : self::$GlobalDBName;
50 
51  # if we don't already have a connection or DB access parameters were supplied
52  $HandleIndex = $this->DBHostName.":".$this->DBName;
53  if (!array_key_exists($HandleIndex, self::$ConnectionHandles)
54  || $UserName || $Password || $DatabaseName || $HostName)
55  {
56  # open connection to DB server
57  self::$ConnectionHandles[$HandleIndex] = mysql_connect(
58  $this->DBHostName, $this->DBUserName,
59  $this->DBPassword, TRUE)
60  or die("Could not connect to database: ".mysql_error());
61 
62  # set local connection handle
63  $this->Handle = self::$ConnectionHandles[$HandleIndex];
64 
65  # select DB
66  mysql_select_db($this->DBName, $this->Handle)
67  or die(mysql_error($this->Handle));
68  }
69  else
70  {
71  # set local connection handle
72  $this->Handle = self::$ConnectionHandles[$HandleIndex];
73  }
74  }
75 
80  function __sleep()
81  {
82  return array("DBUserName", "DBPassword", "DBHostName", "DBName");
83  }
87  function __wakeup()
88  {
89  # open connection to DB server
90  $this->Handle = mysql_connect(
91  $this->DBHostName, $this->DBUserName, $this->DBPassword)
92  or die("could not connect to database");
93 
94  # select DB
95  mysql_select_db($this->DBName, $this->Handle)
96  or die(mysql_error($this->Handle));
97  }
107  static function SetGlobalServerInfo($UserName, $Password, $HostName = "localhost")
108  {
109  # save default DB access parameters
110  self::$GlobalDBUserName = $UserName;
111  self::$GlobalDBPassword = $Password;
112  self::$GlobalDBHostName = $HostName;
113 
114  # clear any existing DB connection handles
115  self::$ConnectionHandles = array();
116  }
117 
122  static function SetGlobalDatabaseName($DatabaseName)
123  {
124  # save new default DB name
125  self::$GlobalDBName = $DatabaseName;
126 
127  # clear any existing DB connection handles
128  self::$ConnectionHandles = array();
129  }
130 
136  function DBHostName() { return $this->DBHostName; }
137 
143  function DBName() { return $this->DBName; }
144 
150  function DBUserName() { return $this->DBUserName; }
151 
159  static function Caching($NewSetting = NULL)
160  {
161  # if cache setting has changed
162  if (($NewSetting !== NULL) && ($NewSetting != self::$CachingFlag))
163  {
164  # save new setting
165  self::$CachingFlag = $NewSetting;
166 
167  # clear any existing cached results
168  self::$QueryResultCache = array();
169  }
170 
171  # return current setting to caller
172  return self::$CachingFlag;
173  }
174 
185  static function AdvancedCaching($NewSetting = NULL)
186  {
187  if ($NewSetting !== NULL)
188  {
189  self::$AdvancedCachingFlag = $NewSetting;
190  }
191  return self::$AdvancedCachingFlag;
192  }
193 
208  function SetQueryErrorsToIgnore($ErrorsToIgnore)
209  {
210  $this->ErrorsToIgnore = $ErrorsToIgnore;
211  }
212 
213  /*@)*/ /* Setup/Initialization */ /*@(*/
215 
223  function Query($QueryString, $FieldName = "")
224  {
225  # if caching is enabled
226  if (self::$CachingFlag)
227  {
228  # if SQL statement is read-only
229  if ($this->IsReadOnlyStatement($QueryString))
230  {
231  # if we have statement in cache
232  if (isset(self::$QueryResultCache[$QueryString]["NumRows"]))
233  {
234  if (self::$QueryDebugOutputFlag)
235  { print("DB-C: $QueryString<br>\n"); }
236 
237  # make sure query result looks okay
238  $this->QueryHandle = TRUE;
239 
240  # increment cache hit counter
241  self::$CachedQueryCounter++;
242 
243  # make local copy of results
244  $this->QueryResults = self::$QueryResultCache[$QueryString];
245  $this->NumRows = self::$QueryResultCache[$QueryString]["NumRows"];
246 
247  # set flag to indicate that results should be retrieved from cache
248  $this->GetResultsFromCache = TRUE;
249  }
250  else
251  {
252  # execute SQL statement
253  $this->QueryHandle = $this->RunQuery($QueryString);
254  if (!is_resource($this->QueryHandle)) { return FALSE; }
255 
256  # save number of rows in result
257  $this->NumRows = mysql_num_rows($this->QueryHandle);
258 
259  # if too many rows to cache
260  if ($this->NumRows >= 50)
261  {
262  # set flag to indicate that query results should not
263  # be retrieved from cache
264  $this->GetResultsFromCache = FALSE;
265  }
266  else
267  {
268  # if advanced caching is enabled
269  if (self::$AdvancedCachingFlag)
270  {
271  # save tables accessed by query
272  self::$QueryResultCache[$QueryString]["TablesAccessed"] =
273  $this->TablesAccessed($QueryString);
274  }
275 
276  # if rows found
277  if ($this->NumRows > 0)
278  {
279  # load query results
280  for ($Row = 0; $Row < $this->NumRows; $Row++)
281  {
282  $this->QueryResults[$Row] =
283  mysql_fetch_assoc($this->QueryHandle);
284  }
285 
286  # cache query results
287  self::$QueryResultCache[$QueryString] = $this->QueryResults;
288  }
289  else
290  {
291  # clear local query results
292  unset($this->QueryResults);
293  }
294 
295  # cache number of rows
296  self::$QueryResultCache[$QueryString]["NumRows"] = $this->NumRows;
297 
298  # set flag to indicate that query results should be retrieved from cache
299  $this->GetResultsFromCache = TRUE;
300  }
301  }
302  }
303  else
304  {
305  # if advanced caching is enabled
306  if (self::$AdvancedCachingFlag)
307  {
308  # if table modified by statement is known
309  $TableModified = $this->TableModified($QueryString);
310  if ($TableModified)
311  {
312  # for each cached query
313  foreach (self::$QueryResultCache
314  as $CachedQueryString => $CachedQueryResult)
315  {
316  # if we know what tables were accessed
317  if ($CachedQueryResult["TablesAccessed"])
318  {
319  # if tables accessed include the one we may modify
320  if (in_array($TableModified, $CachedQueryResult["TablesAccessed"]))
321  {
322  # clear cached query results
323  unset($GLOBALS["APDBQueryResultCache"][$CachedQueryString]);
324  }
325  }
326  else
327  {
328  # clear cached query results
329  unset($GLOBALS["APDBQueryResultCache"][$CachedQueryString]);
330  }
331  }
332  }
333  else
334  {
335  # clear entire query result cache
336  self::$QueryResultCache = array();
337  }
338  }
339  else
340  {
341  # clear entire query result cache
342  self::$QueryResultCache = array();
343  }
344 
345  # execute SQL statement
346  $this->QueryHandle = $this->RunQuery($QueryString);
347  if ($this->QueryHandle === FALSE) { return FALSE; }
348 
349  # set flag to indicate that query results should not be retrieved from cache
350  $this->GetResultsFromCache = FALSE;
351  }
352 
353  # reset row counter
354  $this->RowCounter = 0;
355 
356  # increment query counter
357  self::$QueryCounter++;
358  }
359  else
360  {
361  # execute SQL statement
362  $this->QueryHandle = $this->RunQuery($QueryString);
363  if ($this->QueryHandle === FALSE) { return FALSE; }
364  }
365 
366  if (($FieldName != "") && ($this->QueryHandle != FALSE))
367  {
368  return $this->FetchField($FieldName);
369  }
370  else
371  {
372  return $this->QueryHandle;
373  }
374  }
375 
388  function ExecuteQueriesFromFile($FileName)
389  {
390  # open file
391  $FHandle = fopen($FileName, "r");
392 
393  # if file open succeeded
394  if ($FHandle !== FALSE)
395  {
396  # while lines left in file
397  $Query = "";
398  $QueryCount = 0;
399  while (!feof($FHandle))
400  {
401  # read in line from file
402  $Line = fgets($FHandle, 32767);
403 
404  # trim whitespace from line
405  $Line = trim($Line);
406 
407  # if line is not empty and not a comment
408  if (!preg_match("/^#/", $Line)
409  && !preg_match("/^--/", $Line)
410  && strlen($Line))
411  {
412  # add line to current query
413  $Query .= " ".$Line;
414 
415  # if line completes a query
416  if (preg_match("/;$/", $Line))
417  {
418  # run query
419  $QueryCount++;
420  $Result = $this->Query($Query);
421  $Query = "";
422 
423  # if query resulted in an error that is not ignorable
424  if ($Result === FALSE)
425  {
426  # stop processing queries and set error code
427  $QueryCount = NULL;
428  break;
429  }
430  }
431  }
432  }
433 
434  # close file
435  fclose($FHandle);
436  }
437 
438  # return number of executed queries to caller
439  return $QueryCount;
440  }
441 
447  function QueryErrMsg()
448  {
449  return $this->ErrMsg;
450  }
451 
457  function QueryErrNo()
458  {
459  return $this->ErrNo;
460  }
461 
468  static function DisplayQueryErrors($NewValue = NULL)
469  {
470  if ($NewValue !== NULL) { self::$DisplayErrors = $NewValue; }
471  return self::$DisplayErrors;
472  }
473 
478  function NumRowsSelected()
479  {
480  # if caching is enabled and query was cached
481  if (self::$CachingFlag && $this->GetResultsFromCache)
482  {
483  # return cached number of rows to caller
484  return $this->NumRows;
485  }
486  else
487  {
488  # call to this method after an unsuccessful query
489  if (!is_resource($this->QueryHandle))
490  {
491  return 0;
492  }
493 
494  # retrieve number of rows and return to caller
495  return mysql_num_rows($this->QueryHandle);
496  }
497  }
498 
504  function FetchRow()
505  {
506  # if caching is enabled and query was cached
507  if (self::$CachingFlag && $this->GetResultsFromCache)
508  {
509  # if rows left to return
510  if ($this->RowCounter < $this->NumRows)
511  {
512  # retrieve row from cache
513  $Result = $this->QueryResults[$this->RowCounter];
514 
515  # increment row counter
516  $this->RowCounter++;
517  }
518  else
519  {
520  # return nothing
521  $Result = FALSE;
522  }
523  }
524  else
525  {
526  # call to this method after successful query
527  if (is_resource($this->QueryHandle))
528  {
529  $Result = mysql_fetch_assoc($this->QueryHandle);
530  }
531 
532  # call to this method after unsuccessful query
533  else
534  {
535  $Result = FALSE;
536  }
537  }
538 
539  # return row to caller
540  return $Result;
541  }
542 
549  function FetchRows($NumberOfRows = NULL)
550  {
551  # assume no rows will be returned
552  $Result = array();
553 
554  # for each available row
555  $RowsFetched = 0;
556  while ((($RowsFetched < $NumberOfRows) || ($NumberOfRows == NULL))
557  && ($Row = $this->FetchRow()))
558  {
559  # add row to results
560  $Result[] = $Row;
561  $RowsFetched++;
562  }
563 
564  # return array of rows to caller
565  return $Result;
566  }
567 
584  function FetchColumn($FieldName, $IndexFieldName = NULL)
585  {
586  $Array = array();
587  while ($Record = $this->FetchRow())
588  {
589  if ($IndexFieldName != NULL)
590  {
591  $Array[$Record[$IndexFieldName]] = $Record[$FieldName];
592  }
593  else
594  {
595  $Array[] = $Record[$FieldName];
596  }
597  }
598  return $Array;
599  }
600 
609  function FetchField($FieldName)
610  {
611  $Record = $this->FetchRow();
612  return isset($Record[$FieldName]) ? $Record[$FieldName] : NULL;
613  }
614 
622  function LastInsertId($TableName)
623  {
624  return (int)$this->Query(
625  "SELECT LAST_INSERT_ID() AS InsertId FROM ".$TableName,
626  "InsertId");
627  }
628 
643  function UpdateValue(
644  $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
645  {
646  # expand condition if supplied
647  if ($Condition != NULL) { $Condition = " WHERE ".$Condition; }
648 
649  # read cached record from database if not already loaded
650  if (!isset($CachedRecord))
651  {
652  $this->Query("SELECT * FROM `".$TableName."` ".$Condition);
653  $CachedRecord = $this->FetchRow();
654  }
655 
656  # if new value supplied
657  if ($NewValue !== DB_NOVALUE)
658  {
659  # update value in database
660  $this->Query("UPDATE `".$TableName."` SET `".$FieldName."` = "
661  .(($NewValue === NULL) ? "NULL" : "'"
662  .mysql_real_escape_string($NewValue)."'")
663  .$Condition);
664 
665  # update value in cached record
666  $CachedRecord[$FieldName] = $NewValue;
667  }
668 
669  # return value from cached record to caller
670  return isset($CachedRecord[$FieldName])
671  ? $CachedRecord[$FieldName] : NULL;
672  }
673 
690  function UpdateIntValue(
691  $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
692  {
693  return $this->UpdateValue($TableName, $FieldName,
694  (($NewValue === DB_NOVALUE) ? DB_NOVALUE : (int)$NewValue),
695  $Condition, $CachedRecord);
696  }
697 
715  $TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
716  {
717  return $this->UpdateValue($TableName, $FieldName,
718  (($NewValue === DB_NOVALUE) ? DB_NOVALUE : (float)$NewValue),
719  $Condition, $CachedRecord);
720  }
721 
722  /*@)*/ /* Data Manipulation */ /*@(*/
724 
731  function LogComment($String)
732  {
733  $this->Query("-- ".$String);
734  }
735 
742  function FieldExists($TableName, $FieldName)
743  {
744  $this->Query("DESC ".$TableName);
745  while ($CurrentFieldName = $this->FetchField("Field"))
746  {
747  if ($CurrentFieldName == $FieldName) { return TRUE; }
748  }
749  return FALSE;
750  }
751 
758  function GetFieldType($TableName, $FieldName)
759  {
760  $this->Query("DESC ".$TableName);
761  return $this->FetchField("Type");
762  }
763 
769  static function QueryDebugOutput($NewSetting)
770  {
771  self::$QueryDebugOutputFlag = $NewSetting;
772  }
773 
779  static function NumQueries()
780  {
781  return self::$QueryCounter;
782  }
783 
790  static function NumCacheHits()
791  {
792  return self::$CachedQueryCounter;
793  }
794 
800  static function CacheHitRate()
801  {
802  if (self::$QueryCounter)
803  {
804  return (self::$CachedQueryCounter / self::$QueryCounter) * 100;
805  }
806  else
807  {
808  return 0;
809  }
810  }
811 
812  /*@)*/ /* Miscellaneous */
813 
814  # ---- PRIVATE INTERFACE -------------------------------------------------
815 
816  protected $DBUserName;
817  protected $DBPassword;
818  protected $DBHostName;
819  protected $DBName;
820 
821  private $Handle;
822  private $QueryHandle;
823  private $QueryResults;
824  private $RowCounter;
825  private $NumRows;
826  private $GetResultsFromCache;
827  private $ErrorsToIgnore = NULL;
828  private $ErrMsg = NULL;
829  private $ErrNo = NULL;
830 
831  private static $DisplayErrors = FALSE;
832 
833  private static $GlobalDBUserName;
834  private static $GlobalDBPassword;
835  private static $GlobalDBHostName;
836  private static $GlobalDBName;
837 
838  # debug output flag
839  private static $QueryDebugOutputFlag = FALSE;
840  # flag for whether caching is turned on
841  private static $CachingFlag = TRUE;
842  # query result advanced caching flag
843  private static $AdvancedCachingFlag = FALSE;
844  # global cache for query results
845  private static $QueryResultCache = array();
846  # stats counters
847  private static $QueryCounter = 0;
848  private static $CachedQueryCounter = 0;
849  # database connection link handles
850  private static $ConnectionHandles = array();
851 
857  private function IsReadOnlyStatement($QueryString)
858  {
859  return preg_match("/^[ ]*SELECT /i", $QueryString) ? TRUE : FALSE;
860  }
861 
868  private function TableModified($QueryString)
869  {
870  # assume we're not going to be able to determine table
871  $TableName = FALSE;
872 
873  # split query into pieces
874  $QueryString = trim($QueryString);
875  $Words = preg_split("/\s+/", $QueryString);
876 
877  # if INSERT statement
878  $WordIndex = 1;
879  if (strtoupper($Words[0]) == "INSERT")
880  {
881  # skip over modifying keywords
882  while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
883  || (strtoupper($Words[$WordIndex]) == "DELAYED")
884  || (strtoupper($Words[$WordIndex]) == "IGNORE")
885  || (strtoupper($Words[$WordIndex]) == "INTO"))
886  {
887  $WordIndex++;
888  }
889 
890  # next word is table name
891  $TableName = $Words[$WordIndex];
892  }
893  # else if UPDATE statement
894  elseif (strtoupper($Words[0]) == "UPDATE")
895  {
896  # skip over modifying keywords
897  while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
898  || (strtoupper($Words[$WordIndex]) == "IGNORE"))
899  {
900  $WordIndex++;
901  }
902 
903  # if word following next word is SET
904  if (strtoupper($Words[$WordIndex + 1]) == "SET")
905  {
906  # next word is table name
907  $TableName = $Words[$WordIndex];
908  }
909  }
910  # else if DELETE statement
911  elseif (strtoupper($Words[0]) == "DELETE")
912  {
913  # skip over modifying keywords
914  while ((strtoupper($Words[$WordIndex]) == "LOW_PRIORITY")
915  || (strtoupper($Words[$WordIndex]) == "IGNORE")
916  || (strtoupper($Words[$WordIndex]) == "QUICK"))
917  {
918  $WordIndex++;
919  }
920 
921  # if next term is FROM
922  if (strtoupper($Words[$WordIndex]) == "FROM")
923  {
924  # next word is table name
925  $WordIndex++;
926  $TableName = $Words[$WordIndex];
927  }
928  }
929 
930  # discard table name if it looks at all suspicious
931  if ($TableName)
932  {
933  if (!preg_match("/[a-zA-Z0-9]+/", $TableName))
934  {
935  $TableName = FALSE;
936  }
937  }
938 
939  # return table name (or lack thereof) to caller
940  return $TableName;
941  }
942 
949  private function TablesAccessed($QueryString)
950  {
951  # assume we're not going to be able to determine tables
952  $TableNames = FALSE;
953 
954  # split query into pieces
955  $QueryString = trim($QueryString);
956  $Words = preg_split("/\s+/", $QueryString);
957  $UQueryString = strtoupper($QueryString);
958  $UWords = preg_split("/\s+/", $UQueryString);
959 
960  # if SELECT statement
961  if ($UWords[0] == "SELECT")
962  {
963  # keep going until we hit FROM or last word
964  $WordIndex = 1;
965  while (($UWords[$WordIndex] != "FROM")
966  && strlen($UWords[$WordIndex]))
967  {
968  $WordIndex++;
969  }
970 
971  # if we hit FROM
972  if ($UWords[$WordIndex] == "FROM")
973  {
974  # for each word after FROM
975  $WordIndex++;
976  while (strlen($UWords[$WordIndex]))
977  {
978  # if current word ends with comma
979  if (preg_match("/,$/", $Words[$WordIndex]))
980  {
981  # strip off comma and add word to table name list
982  $TableNames[] = substr($Words[$WordIndex], 0, -1);
983  }
984  else
985  {
986  # add word to table name list
987  $TableNames[] = $Words[$WordIndex];
988 
989  # if next word is not comma
990  $WordIndex++;
991  if ($Words[$WordIndex] != ",")
992  {
993  # if word begins with comma
994  if (preg_match("/^,/", $Words[$WordIndex]))
995  {
996  # strip off comma (NOTE: modifies $Words array!)
997  $Words[$WordIndex] = substr($Words[$WordIndex], 1);
998 
999  # decrement index so we start with this word next pass
1000  $WordIndex--;
1001  }
1002  else
1003  {
1004  # stop scanning words (non-basic JOINs not yet handled)
1005  break;
1006  }
1007  }
1008  }
1009 
1010  # move to next word
1011  $WordIndex++;
1012  }
1013  }
1014  }
1015 
1016  # discard table names if they look at all suspicious
1017  if ($TableNames)
1018  {
1019  foreach ($TableNames as $Name)
1020  {
1021  if (!preg_match("/^[a-zA-Z0-9]+$/", $Name))
1022  {
1023  $TableNames = FALSE;
1024  break;
1025  }
1026  }
1027  }
1028 
1029  # return table name (or lack thereof) to caller
1030  return $TableNames;
1031  }
1032 
1039  private function RunQuery($QueryString)
1040  {
1041  if (self::$QueryDebugOutputFlag) { $QueryStartTime = microtime(TRUE); }
1042  $this->QueryHandle = mysql_query($QueryString, $this->Handle);
1043  if (self::$QueryDebugOutputFlag)
1044  {
1045  print "DB: ".$QueryString." ["
1046  .sprintf("%.2f", microtime(TRUE) - $QueryStartTime)
1047  ."s]"."<br>\n";
1048  }
1049  if (($this->QueryHandle === FALSE) && $this->ErrorsToIgnore)
1050  {
1051  foreach ($this->ErrorsToIgnore as $SqlPattern => $ErrMsgPattern)
1052  {
1053  if (preg_match($SqlPattern, $QueryString)
1054  && preg_match($ErrMsgPattern, mysql_error($this->Handle)))
1055  {
1056  $this->QueryHandle = TRUE;
1057  break;
1058  }
1059  }
1060  }
1061 
1062  if ($this->QueryHandle === FALSE)
1063  {
1064  $this->ErrMsg = mysql_error($this->Handle);
1065  $this->ErrNo = mysql_errno($this->Handle);
1066  $this->NumRows = 0;
1067  if (self::$DisplayErrors)
1068  {
1069  print("<b>SQL Error:</b> <i>".$this->ErrMsg
1070  ."</i> (".$this->ErrNo.")<br/>\n");
1071  print("<b>SQL Statement:</b> <i>"
1072  .htmlspecialchars($QueryString)."</i><br/>\n");
1073  }
1074  }
1075  return $this->QueryHandle;
1076  }
1077 }
1078 
1079 # define return values (numerical values correspond to MySQL error codes)
1080 define("DB_OKAY", 0);
1081 define("DB_ERROR", 1);
1082 define("DB_ACCESSDENIED", 2);
1083 define("DB_UNKNOWNDB", 3);
1084 define("DB_UNKNOWNTABLE", 4);
1085 define("DB_SYNTAXERROR", 5);
1086 define("DB_DBALREADYEXISTS", 6);
1087 define("DB_DBDOESNOTEXIST", 7);
1088 define("DB_DISKFULL", 8);
1089 
1090 # define value to designate omitted arguments (so DB values can be set to NULL)
1091 define("DB_NOVALUE", "!-_-_-DB_NOVALUE-_-_-!");
1092 
1093 # MySQL error code mapping
1095  1045 => DB_ACCESSDENIED,
1096  1049 => DB_UNKNOWNDB,
1097  1046 => DB_UNKNOWNTABLE,
1098  1064 => DB_SYNTAXERROR,
1099  1007 => DB_DBALREADYEXISTS, # ? (not sure)
1100  1008 => DB_DBDOESNOTEXIST, # ? (not sure)
1101  1021 => DB_DISKFULL, # ? (not sure)
1102  );
1103 
1104 ?>
QueryErrMsg()
Get most recent error message text set by Query().
static Caching($NewSetting=NULL)
Get or set whether query result caching is currently enabled.
const DB_UNKNOWNDB
static SetGlobalDatabaseName($DatabaseName)
Set default database name.
SetQueryErrorsToIgnore($ErrorsToIgnore)
Set query errors to ignore.
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.
const DB_SYNTAXERROR
SQL database abstraction object with smart query caching.
const DB_NOVALUE
DBUserName()
Get name used to connect with database server.
LastInsertId($TableName)
Get ID of row added by the last SQL &quot;INSERT&quot; statement.
Database($UserName=NULL, $Password=NULL, $DatabaseName=NULL, $HostName=NULL)
Object constructor.
FetchRow()
Get next database row retrieved by most recent query.
static SetGlobalServerInfo($UserName, $Password, $HostName="localhost")
const DB_DBALREADYEXISTS
PHP
Definition: OAIClient.php:39
GetFieldType($TableName, $FieldName)
Get field (column) type.
NumRowsSelected()
Get number of rows returned by last 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.
const DB_ACCESSDENIED
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().
$APDBErrorCodeMappings
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.
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.
const DB_DBDOESNOTEXIST
const DB_UNKNOWNTABLE
const DB_DISKFULL