From 3b0a002423285930cfd9b88737928213b1137cc1 Mon Sep 17 00:00:00 2001 From: mukhtar Date: Tue, 14 Jan 2003 09:03:09 +0000 Subject: [PATCH] no message --- lib/db.inc | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+), 0 deletions(-) create mode 100644 lib/db.inc diff --git a/lib/db.inc b/lib/db.inc new file mode 100644 index 0000000..db3f96c --- /dev/null +++ b/lib/db.inc @@ -0,0 +1,167 @@ +Host = $default->owl_db_host; + $this->Database = $default->owl_db_name; + $this->User = $default->owl_db_user; + $this->Password = $default->owl_db_pass; + } + // END wes changes + + /** + * Create a query from the provided paramaters. The ID column + * is seleted by default + * + * @param $sTableName Table to query + * @param $aColumns Columns in table + * @param $sWhereClause Where clause (optional) + * @param $sOrderByClause Order by clause (optional) + */ + function createSQLQuery($sTableName, $aColumns, $sWhereClause = null, $sOrderByClause = null) { + $this->sLastTableName = $sTableName; + $this->sLastWhereCluase = $sWhereClause; + $this->sLastOrderByClause = $sOrderByClause; + + $this->sQuery = "SELECT ID, "; + + for( $i = 0; $i < count($aColumns) - 1; $i++ ) { + $this->sQuery = $this->sQuery . $aColumns[$i] . ","; + } + + $this->sQuery .= $aColumns[count($aColumns) - 1] . " "; + $this->sQuery .= "FROM " . $sTableName . " "; + + if (isset($sWhereClause)) { + $this->sQuery .= "WHERE " . $sWhereClause . " "; + } + + if (isset($sOrderByClause)) { + $this->sQuery .= "ORDER BY " . $sOrderByClause . " "; + } + + $this->query($this->sQuery); + + } + + /** + Create a query from the provided paramaters, specifying a limit and an offset. + The ID column is selected by default + + @param $sTableName Table to query + @param $aColumns Columns in table + @param $iOffset Offset + @param $iLimit Limit + @param $sWhereClause Where clause (optional) + @param $sOrderByClause Order by clause (optional) + */ + + function createSQLQueryWithOffset($sTableName, $aColumns, $iOffset, $iLimit, $sWhereClause = null, $sOrderByClause = null) { + $this->sLastTableName = $sTableName; + $this->sLastWhereCluase = $sWhereClause; + $this->sLastOrderByClause = $sOrderByClause; + + $this->sQuery = "SELECT ID, "; + + for( $i = 0; $i < count($aColumns) - 1; $i++ ) { + $this->sQuery = $this->sQuery . $aColumns[$i] . ","; + } + + $this->sQuery .= $aColumns[count($aColumns) - 1] . " "; + $this->sQuery .= "FROM " . $sTableName . " "; + + + + if (isset($sWhereClause)) { + $this->sQuery .= "WHERE " . $sWhereClause . " "; + } + + if (isset($sOrderByClause)) { + $this->sQuery .= "ORDER BY " . $sOrderByClause . " "; + } + + $this->sQuery .= "LIMIT " . $iOffset . ", " . $iLimit; + $this->query($this->sQuery); + } + + /** + * Get the result count for the previously executed query. Meant + * to be used in conjuction with createSSQLQueryWithOffset so that + * the total number of results can be calculated + * + * @return int row count + */ + function & getLastQueryResultCount() { + if (isset($this->sLastTableName)) { + $sCountResultQuery = "SELECT COUNT(*) AS ResultCount FROM " . $this->sLastTableName; + + if (isset($this->sLastWhereClause)) { + sCountResultQuery . " WHERE " . $this->sLastWhereClause; + } + $this->query($sCountResultQuery); + $this->next_record(); + return $this->f("ResultCount"); + } else { + return 0; + } + } + + /** + * Execute the query and return the results + * + * @returns Results of query + */ + function & getQueryResults() { + $result = null; + if (isset($this->sQuery)) { + $result = $this->query($this->sQuery); + } + return $result; + } + + /** + * Display any database errors encountered + */ + function haltmsg($msg) { + printf("Database error: %s
\n", $msg); + printf("SQL Error: %s (%s)
\n",$this->Errno, $this->Error); + } +} + +?> \ No newline at end of file -- libgit2 0.21.4