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()


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@184 a1433add-5e2c-0410-b055-b7f2511e0802
postfixadmin-2.3
Christian Boltz 17 years ago
parent ae74e7a70c
commit 5acd24515f

@ -675,7 +675,7 @@ function divide_quota ($quota)
// //
// check_owner // 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) // Call: check_owner (string admin, string domain)
// //
function check_owner ($username, $domain) function check_owner ($username, $domain)
@ -1532,21 +1532,54 @@ function db_delete ($table,$where,$delete)
* Call: db_insert (string table, array values) * Call: db_insert (string table, array values)
* @param String $table - table name * @param String $table - table name
* @param array - key/value map of data to insert into the table. * @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) {
$table = table_by_key ($table); $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"); $result = db_query ("INSERT INTO $table $sql_values");
if ($result['rows'] >= 1)
{
return $result['rows']; 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
{ foreach($timestamp as $key) {
return true; $sql_values[$key] = escape_string($key) . "=now()";
} }
$sql="UPDATE $table SET ".implode(",",$sql_values)." WHERE $where";
$result = db_query ($sql);
return $result['rows'];
} }

Loading…
Cancel
Save