Permalink
Browse files

Return to safee and correct code for database function

  • Loading branch information...
1 parent be72b05 commit 8e40f3aa3655d8202bb4adabc5205616f66942cb @acidvertigo acidvertigo committed Aug 17, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 catalog/includes/functions/database.php
@@ -52,13 +52,15 @@ function tep_db_query($query, $link = 'db_link') {
}
function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
+ reset($data);
if ($action == 'insert') {
$query = 'insert into ' . $table . ' (';
- foreach($data as $columns) {
+ while (list($columns, ) = each($data)) {
$query .= $columns . ', ';
}
$query = substr($query, 0, -2) . ') values (';
- foreach($data as $value) {
+ reset($data);
+ while (list(, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= 'now(), ';
@@ -74,7 +76,7 @@ function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $li
$query = substr($query, 0, -2) . ')';
} elseif ($action == 'update') {
$query = 'update ' . $table . ' set ';
- foreach($data as $columns => $value) {
+ foreach ($data as $columns => $value) {
switch ((string)$value) {
case 'now()':
$query .= $columns . ' = now(), ';
@@ -139,7 +141,7 @@ function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(tep_sanitize_string(stripslashes($string)));
} elseif (is_array($string)) {
- foreach($string as $key => $value) {
+ foreach ($string as $key => $value) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;

0 comments on commit 8e40f3a

Please sign in to comment.