ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/functions/database.php
Go to the documentation of this file.
00001 <?php
00011   function zen_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
00012     global $db;
00013     reset($data);
00014     if ($action == 'insert') {
00015       $query = 'insert into ' . $table . ' (';
00016       while (list($columns, ) = each($data)) {
00017         $query .= $columns . ', ';
00018       }
00019       $query = substr($query, 0, -2) . ') values (';
00020       reset($data);
00021       while (list(, $value) = each($data)) {
00022         switch ((string)$value) {
00023           case 'now()':
00024             $query .= 'now(), ';
00025             break;
00026           case 'null':
00027             $query .= 'null, ';
00028             break;
00029           default:
00030             $query .= '\'' . zen_db_input($value) . '\', ';
00031             break;
00032         }
00033       }
00034       $query = substr($query, 0, -2) . ')';
00035     } elseif ($action == 'update') {
00036       $query = 'update ' . $table . ' set ';
00037       while (list($columns, $value) = each($data)) {
00038         switch ((string)$value) {
00039           case 'now()':
00040             $query .= $columns . ' = now(), ';
00041             break;
00042           case 'null':
00043             $query .= $columns .= ' = null, ';
00044             break;
00045           default:
00046             $query .= $columns . ' = \'' . zen_db_input($value) . '\', ';
00047             break;
00048         }
00049       }
00050       $query = substr($query, 0, -2) . ' where ' . $parameters;
00051     }
00052 
00053     return $db->Execute($query);
00054   }
00055 
00056   function zen_db_insert_id() {
00057     return mysql_insert_id();
00058   }
00059 
00060   function zen_db_output($string) {
00061     return htmlspecialchars($string);
00062   }
00063 
00064   function zen_db_input($string) {
00065     return addslashes($string);
00066   }
00067 
00068   function zen_db_prepare_input($string, $trimspace = true) {
00069     if (is_string($string)) {
00070       if ($trimspace == true) {
00071         return trim(stripslashes($string));
00072       } else {
00073         return stripslashes($string);
00074       }
00075     } elseif (is_array($string)) {
00076       reset($string);
00077       while (list($key, $value) = each($string)) {
00078         $string[$key] = zen_db_prepare_input($value);
00079       }
00080       return $string;
00081     } else {
00082       return $string;
00083     }
00084   }
 All Data Structures Namespaces Files Functions Variables Enumerations