[PHPVortex-Commit] phpvortex DB_Base.class.php,1.4,1.5
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2004-09-29 20:05:08
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18305 Modified Files: DB_Base.class.php Log Message: Added the member functions Insert(), Update() and Delete() to DB_Base Index: DB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/DB_Base.class.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DB_Base.class.php 29 Sep 2004 15:50:49 -0000 1.4 --- DB_Base.class.php 29 Sep 2004 20:04:59 -0000 1.5 *************** *** 86,89 **** --- 86,139 ---- /** + * Execute a INSERT INTO query at the database. + * + * @param string $table Table to insert into. + * @param array $values Fields and values to insert, as 'field' => 'value'. + * @return RS_Base Returns a RecordSet object if there is a result to the query or FALSE if a error occurred. + */ + function &Insert($table, $values) + { + $fl = ''; + $vl = ''; + foreach($values as $f => $v) { + $fl = (strlen($fl)?', ':'') . $f; + $vl = (strlen($vl)?', ':'') . $v; + } + $sql = "INSERT INTO $table ($fl) VALUES ($vl)"; + return $this->Query($sql); + } + + /** + * Execute a UPDATE query at the database. + * + * @param string $table Table to update. + * @param array $values Fields and values to update, as 'field' => 'value'. + * @param string $where Where clause to the query. + * @return RS_Base Returns a RecordSet object if there is a result to the query or FALSE if a error occurred. + */ + function &Update($table, $values, $where) + { + $sl = ''; + foreach($values as $f => $v) { + $sl = (strlen($sl)?', ':'') . "$f = $v"; + } + $sql = "UPDATE $table SET $sl WHERE $where"; + return $this->Query($sql); + } + + /** + * Execute a DELETE query at the database. + * + * @param string $table Table to update. + * @param string $where Where clause to the query. + * @return RS_Base Returns a RecordSet object if there is a result to the query or FALSE if a error occurred. + */ + function &Delete($table, $where) + { + $sql = "DELETE FROM $table WHERE $where"; + return $this->Query($sql); + } + + /** * Close the connection to the database if still connected. * |