Commit 3b0a002423285930cfd9b88737928213b1137cc1
1 parent
3f7beea4
no message
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@158 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
167 additions
and
0 deletions
lib/db.inc
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * class Owl_DB extends DB_Sql | ||
| 5 | + * | ||
| 6 | + * This class is used for DB connections | ||
| 7 | + * | ||
| 8 | + * @version v 1.1.1.1 2002/12/04 | ||
| 9 | + * @author michael | ||
| 10 | + * @package Owl | ||
| 11 | + */ | ||
| 12 | + | ||
| 13 | +class Owl_DB extends DB_Sql { | ||
| 14 | + | ||
| 15 | + /** Class name */ | ||
| 16 | + var $classname = "Owl_DB"; | ||
| 17 | + | ||
| 18 | + // BEGIN wes changes -- moved these settings to config/owl.php | ||
| 19 | + // Server where the database resides | ||
| 20 | + | ||
| 21 | + /** Host name. Retrieved from config/owl.php */ | ||
| 22 | + var $Host = ""; | ||
| 23 | + /** Database name */ | ||
| 24 | + var $Database = ""; | ||
| 25 | + /** Database user */ | ||
| 26 | + var $User = ""; | ||
| 27 | + /** Database user password */ | ||
| 28 | + var $Password = ""; | ||
| 29 | + /** Query to execute */ | ||
| 30 | + var $sQuery; | ||
| 31 | + /** Name of table last query was executed on*/ | ||
| 32 | + var $sLastTableName; | ||
| 33 | + /** Where clause last used in query execution */ | ||
| 34 | + var $sLastWhereClause; | ||
| 35 | + /** Order by clause last used in query execution */ | ||
| 36 | + var $sLastOrderByClause; | ||
| 37 | + | ||
| 38 | + /** Default Constructor */ | ||
| 39 | + function Owl_DB() { | ||
| 40 | + global $default; | ||
| 41 | + $this->Host = $default->owl_db_host; | ||
| 42 | + $this->Database = $default->owl_db_name; | ||
| 43 | + $this->User = $default->owl_db_user; | ||
| 44 | + $this->Password = $default->owl_db_pass; | ||
| 45 | + } | ||
| 46 | + // END wes changes | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Create a query from the provided paramaters. The ID column | ||
| 50 | + * is seleted by default | ||
| 51 | + * | ||
| 52 | + * @param $sTableName Table to query | ||
| 53 | + * @param $aColumns Columns in table | ||
| 54 | + * @param $sWhereClause Where clause (optional) | ||
| 55 | + * @param $sOrderByClause Order by clause (optional) | ||
| 56 | + */ | ||
| 57 | + function createSQLQuery($sTableName, $aColumns, $sWhereClause = null, $sOrderByClause = null) { | ||
| 58 | + $this->sLastTableName = $sTableName; | ||
| 59 | + $this->sLastWhereCluase = $sWhereClause; | ||
| 60 | + $this->sLastOrderByClause = $sOrderByClause; | ||
| 61 | + | ||
| 62 | + $this->sQuery = "SELECT ID, "; | ||
| 63 | + | ||
| 64 | + for( $i = 0; $i < count($aColumns) - 1; $i++ ) { | ||
| 65 | + $this->sQuery = $this->sQuery . $aColumns[$i] . ","; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + $this->sQuery .= $aColumns[count($aColumns) - 1] . " "; | ||
| 69 | + $this->sQuery .= "FROM " . $sTableName . " "; | ||
| 70 | + | ||
| 71 | + if (isset($sWhereClause)) { | ||
| 72 | + $this->sQuery .= "WHERE " . $sWhereClause . " "; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + if (isset($sOrderByClause)) { | ||
| 76 | + $this->sQuery .= "ORDER BY " . $sOrderByClause . " "; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + $this->query($this->sQuery); | ||
| 80 | + | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + Create a query from the provided paramaters, specifying a limit and an offset. | ||
| 85 | + The ID column is selected by default | ||
| 86 | + | ||
| 87 | + @param $sTableName Table to query | ||
| 88 | + @param $aColumns Columns in table | ||
| 89 | + @param $iOffset Offset | ||
| 90 | + @param $iLimit Limit | ||
| 91 | + @param $sWhereClause Where clause (optional) | ||
| 92 | + @param $sOrderByClause Order by clause (optional) | ||
| 93 | + */ | ||
| 94 | + | ||
| 95 | + function createSQLQueryWithOffset($sTableName, $aColumns, $iOffset, $iLimit, $sWhereClause = null, $sOrderByClause = null) { | ||
| 96 | + $this->sLastTableName = $sTableName; | ||
| 97 | + $this->sLastWhereCluase = $sWhereClause; | ||
| 98 | + $this->sLastOrderByClause = $sOrderByClause; | ||
| 99 | + | ||
| 100 | + $this->sQuery = "SELECT ID, "; | ||
| 101 | + | ||
| 102 | + for( $i = 0; $i < count($aColumns) - 1; $i++ ) { | ||
| 103 | + $this->sQuery = $this->sQuery . $aColumns[$i] . ","; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + $this->sQuery .= $aColumns[count($aColumns) - 1] . " "; | ||
| 107 | + $this->sQuery .= "FROM " . $sTableName . " "; | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + | ||
| 111 | + if (isset($sWhereClause)) { | ||
| 112 | + $this->sQuery .= "WHERE " . $sWhereClause . " "; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + if (isset($sOrderByClause)) { | ||
| 116 | + $this->sQuery .= "ORDER BY " . $sOrderByClause . " "; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + $this->sQuery .= "LIMIT " . $iOffset . ", " . $iLimit; | ||
| 120 | + $this->query($this->sQuery); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Get the result count for the previously executed query. Meant | ||
| 125 | + * to be used in conjuction with createSSQLQueryWithOffset so that | ||
| 126 | + * the total number of results can be calculated | ||
| 127 | + * | ||
| 128 | + * @return int row count | ||
| 129 | + */ | ||
| 130 | + function & getLastQueryResultCount() { | ||
| 131 | + if (isset($this->sLastTableName)) { | ||
| 132 | + $sCountResultQuery = "SELECT COUNT(*) AS ResultCount FROM " . $this->sLastTableName; | ||
| 133 | + | ||
| 134 | + if (isset($this->sLastWhereClause)) { | ||
| 135 | + sCountResultQuery . " WHERE " . $this->sLastWhereClause; | ||
| 136 | + } | ||
| 137 | + $this->query($sCountResultQuery); | ||
| 138 | + $this->next_record(); | ||
| 139 | + return $this->f("ResultCount"); | ||
| 140 | + } else { | ||
| 141 | + return 0; | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * Execute the query and return the results | ||
| 147 | + * | ||
| 148 | + * @returns Results of query | ||
| 149 | + */ | ||
| 150 | + function & getQueryResults() { | ||
| 151 | + $result = null; | ||
| 152 | + if (isset($this->sQuery)) { | ||
| 153 | + $result = $this->query($this->sQuery); | ||
| 154 | + } | ||
| 155 | + return $result; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * Display any database errors encountered | ||
| 160 | + */ | ||
| 161 | + function haltmsg($msg) { | ||
| 162 | + printf("</td></table><b>Database error:</b> %s<br>\n", $msg); | ||
| 163 | + printf("<b>SQL Error</b>: %s (%s)<br>\n",$this->Errno, $this->Error); | ||
| 164 | + } | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +?> | ||
| 0 | \ No newline at end of file | 168 | \ No newline at end of file |