Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Base.php

00001 <?php
00002 include_once(GALAXIA_LIBRARY.'/src/common/Observable.php');
00005 
00009 class Base extends Observable {
00010   var $db;  // The ADODB object used to access the database
00011         var $num_queries = 0;
00012 
00013   // Constructor receiving a ADODB database object.
00014   function Base($db)
00015   {
00016     if(!$db) {
00017       die("Invalid db object passed to Base constructor");
00018     }
00019     $this->db = $db;
00020   }
00021 
00022         // copied from tikilib.php
00023         function query($query, $values = null, $numrows = -1, $offset = -1, $reporterrors = true) {
00024                 $this->convert_query($query);
00025                 if ($numrows == -1 && $offset == -1)
00026                         $result = $this->db->Execute($query, $values);
00027                 else
00028                         $result = $this->db->SelectLimit($query, $numrows, $offset, $values);
00029                 if (!$result && $reporterrors)
00030                         $this->sql_error($query, $values, $result);
00031                 $this->num_queries++;
00032                 return $result;
00033         }
00034 
00035         function getOne($query, $values = null, $reporterrors = true) {
00036                 $this->convert_query($query);
00037                 $result = $this->db->SelectLimit($query, 1, 0, $values);
00038                 if (!$result && $reporterrors)
00039                         $this->sql_error($query, $values, $result);
00040 
00041                 $res = $result->fetchRow();
00042                 $this->num_queries++;
00043                 if ($res === false)
00044                         return (NULL); //simulate pears behaviour
00045                 list($key, $value) = each($res);
00046                 return $value;
00047         }
00048 
00049         function sql_error($query, $values, $result) {
00050                 global $ADODB_LASTDB;
00051 
00052                 trigger_error($ADODB_LASTDB . " error:  " . $this->db->ErrorMsg(). " in query:<br/>" . $query . "<br/>", E_USER_WARNING);
00053                 // only for debugging.
00054                 print_r($values);
00055                 //echo "<br/>";
00056                 die;
00057         }
00058 
00059         // functions to support DB abstraction
00060         function convert_query(&$query) {
00061                 global $ADODB_LASTDB;
00062 
00063                 switch ($ADODB_LASTDB) {
00064                 case "oci8":
00065                         $query = preg_replace("/`/", "\"", $query);
00066                         // convert bind variables - adodb does not do that 
00067                         $qe = explode("?", $query);
00068                         $query = '';
00069                         for ($i = 0; $i < sizeof($qe) - 1; $i++) {
00070                                 $query .= $qe[$i] . ":" . $i;
00071                         }
00072                         $query .= $qe[$i];
00073                         break;
00074                 case "postgres7":
00075                 case "sybase":
00076                         $query = preg_replace("/`/", "\"", $query);
00077                         break;
00078                 }
00079         }
00080 
00081         function convert_sortmode($sort_mode) {
00082                 global $ADODB_LASTDB;
00083 
00084                 switch ($ADODB_LASTDB) {
00085                 case "pgsql72":
00086                 case "postgres7":
00087                 case "oci8":
00088                 case "sybase":
00089                         // Postgres needs " " around column names
00090                         //preg_replace("#([A-Za-z]+)#","\"\$1\"",$sort_mode);
00091                         $sort_mode = str_replace("_", "\" ", $sort_mode);
00092                         $sort_mode = "\"" . $sort_mode;
00093                         break;
00094                 case "mysql3":
00095                 case "mysql":
00096                 default:
00097                         $sort_mode = str_replace("_", "` ", $sort_mode);
00098                         $sort_mode = "`" . $sort_mode;
00099                         break;
00100                 }
00101                 return $sort_mode;
00102         }
00103 
00104         function convert_binary() {
00105                 global $ADODB_LASTDB;
00106 
00107                 switch ($ADODB_LASTDB) {
00108                 case "pgsql72":
00109                 case "oci8":
00110                 case "postgres7":
00111                         return;
00112                         break;
00113                 case "mysql3":
00114                 case "mysql":
00115                         return "binary";
00116                         break;
00117                 }
00118         }
00119 
00120         function qstr($string, $quoted = null)
00121         {
00122                 if (!isset($quoted)) {
00123                         $quoted = get_magic_quotes_gpc();
00124                 }
00125                 return $this->db->qstr($string,$quoted);
00126         }
00127 
00128 } //end of class
00129 
00130 ?>

Generated on Mon Jun 7 16:37:37 2004 for Galaxia by doxygen 1.3.4