[Openfirst-cvscommit] base/includes dbase.php,1.6,1.7
Brought to you by:
xtimg
From: Jamie <ast...@us...> - 2005-08-24 02:32:53
|
Update of /cvsroot/openfirst/base/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2701/includes Modified Files: dbase.php Log Message: Added select(), update(), and replace() methods (from MediaWiki), so you don't have to hack together strings. Index: dbase.php =================================================================== RCS file: /cvsroot/openfirst/base/includes/dbase.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dbase.php 30 Jun 2005 02:33:43 -0000 1.6 --- dbase.php 24 Aug 2005 02:32:42 -0000 1.7 *************** *** 451,454 **** --- 451,518 ---- return $value; } + + /** SELECT wrapper. + * Copied from MediaWiki. + * $options does nothing, currently. + */ + function select( $table, $vars, $conds='', $options = array() ) + { + $vars = $this->quoteField( $vars ); + if( is_array( $table ) ) { + $from = ' FROM ' . $this->quoteTable( $table ); + } elseif ($table!='') { + $from = ' FROM ' . $this->quoteTable( $table ); + } else { + $from = ''; + } + + #list( $useIndex, $tailOpts ) = $this->makeSelectOptions( (array)$options ); + $useIndex = $tailOpts = ''; + + $cols = $this->quoteField($vars); + + if( !empty( $conds ) ) { + if ( is_array( $conds ) ) { + $conds = $this->quoteFDPairs( $conds, ' AND ' ); + } + $sql = "SELECT $cols $from $useIndex WHERE $conds $tailOpts"; + } else { + $sql = "SELECT $cols $from $useIndex $tailOpts"; + } + return $this->query( $sql ); + } + + /** UPDATE wrapper, takes a condition array and a SET array. + * Copied from MediaWiki. + * + * @param string $table The table to UPDATE + * @param array $values An array of values to SET + * @param array $conds An array of conditions (WHERE) + * @param array $options Nothing (was an array of UPDATE options, can be one or + * more of IGNORE, LOW_PRIORITY) + */ + function update( $table, $values, $conds, $options = array() ) { + $table = $this->quoteTable( $table ); + #$opts = $this->makeUpdateOptions( $options ); + $opts = ''; + $sql = "UPDATE $opts $table SET " . $this->quoteFDPairs( $values ); + if ( $conds != '*' ) { + $sql .= " WHERE " . $this->quoteFDPairs( $conds, ' AND ' ); + } + return $this->query( $sql ); + } + + /** REPLACE query wrapper. + * Copied from MediaWiki (but removed the fancy stuff). + * + * @param string $table The table to perform it on. + * @param array $values An array of values to use in a SET clause. + */ + function replace( $table, $values ) { + $table = $this->quoteTable( $table ); + + $sql = "REPLACE INTO $table SET ".$this->quoteFDPairs($values); + return $this->query( $sql ); + } } ?> |