Using tokens to build where clause in autoExecute
| From: | Mads Mohr Christensen | Date: | Mon, 05 May 2003 13:00:26 +0000 |
| Subject: | Using tokens to build where clause in autoExecute | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-15881@lists.php.net to get a copy of this message | ||
Hi
I was just trying out the prepare/execute provided by DB/common.php and did
some changes:
Index: common.php
===================================================================
RCS file: /repository/pear/DB/DB/common.php,v
retrieving revision 1.14
diff -u -r1.14 common.php
--- common.php 31 Mar 2003 06:30:42 -0000 1.14
+++ common.php 5 May 2003 12:00:50 -0000
@@ -465,9 +465,12 @@
* @see autoPrepare
* @access public
*/
- function autoExecute($table, $fields_values, $mode =
DB_AUTOQUERY_INSERT, $where = false)
+ function autoExecute($table, $fields_values, $mode =
DB_AUTOQUERY_INSERT, $where = false, $where_values = false)
{
$sth = $this->autoPrepare($table, array_keys($fields_values),
$mode, $where);
+ if ($where_values) {
+ $fields_values = array_merge($fields_values, $where_values);
+ }
return $this->execute($sth, array_values($fields_values));
}
This makes this update possible:
$table_name = 'mytable';
$fields_values = array(
'textfield' => 'whee'
);
$id = 1;
$result = $db->autoExecute($table_name, $fields_values, DB_AUTOQUERY_UPDATE,
'id = ?', $id);
or
$result = $db->autoExecute($table_name, $fields_values, DB_AUTOQUERY_UPDATE,
'id = ? AND textfield = ?', array($id, 'spam'));
Is this something worth adding or should i continue to use the old method of
building where clauses?
Regards
Mads