95 lines
3.3 KiB
PHP
Executable File
95 lines
3.3 KiB
PHP
Executable File
<?php
|
|
//
|
|
// +----------------------------------------------------------------------+
|
|
// |zen-cart Open Source E-commerce |
|
|
// +----------------------------------------------------------------------+
|
|
// | Copyright (c) 2003 The zen-cart developers |
|
|
// | |
|
|
// | http://www.zen-cart.com/index.php |
|
|
// | |
|
|
// | Portions Copyright (c) 2003 osCommerce |
|
|
// +----------------------------------------------------------------------+
|
|
// | This source file is subject to version 2.0 of the GPL license, |
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
// | available through the world-wide-web at the following url: |
|
|
// | http://www.zen-cart.com/license/2_0.txt. |
|
|
// | If you did not receive a copy of the zen-cart license and are unable |
|
|
// | to obtain it through the world-wide-web, please send a note to |
|
|
// | license@zen-cart.com so we can mail you a copy immediately. |
|
|
// +----------------------------------------------------------------------+
|
|
// $Id: database.php 1969 2005-09-13 06:57:21Z drbyte $
|
|
//
|
|
|
|
|
|
function zen_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
|
|
global $db;
|
|
reset($data);
|
|
if ($action == 'insert') {
|
|
$query = 'insert into ' . $table . ' (';
|
|
while (list($columns, ) = each($data)) {
|
|
$query .= $columns . ', ';
|
|
}
|
|
$query = substr($query, 0, -2) . ') values (';
|
|
reset($data);
|
|
while (list(, $value) = each($data)) {
|
|
switch ((string)$value) {
|
|
case 'now()':
|
|
$query .= 'now(), ';
|
|
break;
|
|
case 'null':
|
|
$query .= 'null, ';
|
|
break;
|
|
default:
|
|
$query .= '\'' . zen_db_input($value) . '\', ';
|
|
break;
|
|
}
|
|
}
|
|
$query = substr($query, 0, -2) . ')';
|
|
} elseif ($action == 'update') {
|
|
$query = 'update ' . $table . ' set ';
|
|
while (list($columns, $value) = each($data)) {
|
|
switch ((string)$value) {
|
|
case 'now()':
|
|
$query .= $columns . ' = now(), ';
|
|
break;
|
|
case 'null':
|
|
$query .= $columns .= ' = null, ';
|
|
break;
|
|
default:
|
|
$query .= $columns . ' = \'' . zen_db_input($value) . '\', ';
|
|
break;
|
|
}
|
|
}
|
|
$query = substr($query, 0, -2) . ' where ' . $parameters;
|
|
}
|
|
|
|
return $db->Execute($query);
|
|
}
|
|
|
|
function zen_db_insert_id() {
|
|
return mysql_insert_id();
|
|
}
|
|
|
|
function zen_db_output($string) {
|
|
return htmlspecialchars($string);
|
|
}
|
|
|
|
function zen_db_input($string) {
|
|
return addslashes($string);
|
|
}
|
|
|
|
function zen_db_prepare_input($string) {
|
|
if (is_string($string)) {
|
|
return trim(stripslashes($string));
|
|
} elseif (is_array($string)) {
|
|
reset($string);
|
|
while (list($key, $value) = each($string)) {
|
|
$string[$key] = zen_db_prepare_input($value);
|
|
}
|
|
return $string;
|
|
} else {
|
|
return $string;
|
|
}
|
|
}
|
|
?>
|