SF.net SVN: postfixadmin: [184] trunk/functions.inc.php
Brought to you by:
christian_boltz,
gingerdog
|
From: <chr...@us...> - 2007-11-04 00:50:05
|
Revision: 184
http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=184&view=rev
Author: christian_boltz
Date: 2007-11-03 17:50:09 -0700 (Sat, 03 Nov 2007)
Log Message:
-----------
functions.php:
- new function db_update ($table, $where, $values, $timestamp = array())
to update a database entry with the values given as array
- added optional $timestamp parameter to db_insert()
Modified Paths:
--------------
trunk/functions.inc.php
Modified: trunk/functions.inc.php
===================================================================
--- trunk/functions.inc.php 2007-11-03 23:32:36 UTC (rev 183)
+++ trunk/functions.inc.php 2007-11-04 00:50:09 UTC (rev 184)
@@ -675,7 +675,7 @@
//
// check_owner
-// Action: Checks if the admin is the owner of the domain.
+// Action: Checks if the admin is the owner of the domain (or global-admin)
// Call: check_owner (string admin, string domain)
//
function check_owner ($username, $domain)
@@ -1532,21 +1532,54 @@
* Call: db_insert (string table, array values)
* @param String $table - table name
* @param array - key/value map of data to insert into the table.
+ * @param array (optional) - array of fields to set to now()
+ * @return int - number of inserted rows
*/
-function db_insert ($table, $values)
+function db_insert ($table, $values, $timestamp = array())
{
- $sql_values = "(" . implode(",",escape_string(array_keys($values))).") VALUES ('".implode("','",escape_string($values))."')";
+ foreach(array_keys($values) as $key) {
+ $values[$key] = "'" . escape_string($values[$key]) . "'";
+ }
+
+ foreach($timestamp as $key) {
+ $values[$key] = "now()";
+ }
+
+ $sql_values = "(" . implode(",",escape_string(array_keys($values))).") VALUES (".implode(",",$values).")";
+
$table = table_by_key ($table);
+echo "*** $sql_values ***"; exit;
+ $result = db_query ("INSERT INTO $table $sql_values");
+ return $result['rows'];
+}
- $result = db_query ("INSERT INTO $table $sql_values");
- if ($result['rows'] >= 1)
- {
- return $result['rows'];
+
+/**
+ * db_update
+ * Action: Updates a specified table
+ * Call: db_update (string table, array values, string where)
+ * @param String $table - table name
+ * @param String - WHERE condition
+ * @param array - key/value map of data to insert into the table.
+ * @param array (optional) - array of fields to set to now()
+ * @return int - number of updated rows
+ */
+function db_update ($table, $where, $values, $timestamp = array())
+{
+ $table = table_by_key ($table);
+
+ foreach(array_keys($values) as $key) {
+ $sql_values[$key] = escape_string($key) . "='" . escape_string($values[$key]) . "'";
}
- else
- {
- return true;
+
+ foreach($timestamp as $key) {
+ $sql_values[$key] = escape_string($key) . "=now()";
}
+
+ $sql="UPDATE $table SET ".implode(",",$sql_values)." WHERE $where";
+
+ $result = db_query ($sql);
+ return $result['rows'];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|