📄 query_factory.php
字号:
}
$obj->result_random = array_rand($obj->result, sizeof($obj->result));
if (is_array($obj->result_random)) {
$zp_ptr = $obj->result_random[$obj->cursor];
} else {
$zp_ptr = $obj->result_random;
}
while (list($key, $value) = each($obj->result[$zp_ptr])) {
if (!ereg('^[0-9]', $key)) {
$obj->fields[$key] = $value;
}
}
$obj->EOF = false;
} else {
$obj->EOF = true;
}
$time_end = explode (' ', microtime());
$query_time = $time_end[1]+$time_end[0]-$time_start[1]-$time_start[0];
$this->total_query_time += $query_time;
$this->count_queries++;
return($obj);
}
function insert_ID() {
return @mysql_insert_id($this->link);
}
function metaColumns($zp_table) {
$res = @mysql_query("select * from " . $zp_table . " limit 1", $this->link);
$num_fields = @mysql_num_fields($res);
for ($i = 0; $i < $num_fields; $i++) {
// modified by zen-cart.cn
$obj[GBcase(@mysql_field_name($res, $i),"upper")] = new queryFactoryMeta($i, $res);
}
return $obj;
}
function get_server_info() {
if ($this->link) {
return mysql_get_server_info($this->link);
} else {
return UNKNOWN;
}
}
function queryCount() {
return $this->count_queries;
}
function queryTime() {
return $this->total_query_time;
}
function perform ($tableName, $tableData, $performType='INSERT', $performFilter='', $debug=false) {
switch (strtolower($performType)) {
case 'insert':
$insertString = "";
$insertString = "INSERT INTO " . $tableName . " (";
foreach ($tableData as $key => $value) {
if ($debug === true) {
echo $value['fieldName'] . '#';
}
$insertString .= $value['fieldName'] . ", ";
}
$insertString = substr($insertString, 0, strlen($insertString)-2) . ') VALUES (';
reset($tableData);
foreach ($tableData as $key => $value) {
$bindVarValue = $this->getBindVarValue($value['value'], $value['type']);
$insertString .= $bindVarValue . ", ";
}
$insertString = substr($insertString, 0, strlen($insertString)-2) . ')';
if ($debug === true) {
echo $insertString;
die();
} else {
$this->execute($insertString);
}
break;
case 'update':
$updateString ="";
$updateString = 'UPDATE ' . $tableName . ' SET ';
foreach ($tableData as $key => $value) {
$bindVarValue = $this->getBindVarValue($value['value'], $value['type']);
$updateString .= $value['fieldName'] . '=' . $bindVarValue . ', ';
}
$updateString = substr($updateString, 0, strlen($updateString)-2);
if ($performFilter != '') {
$updateString .= ' WHERE ' . $performFilter;
}
if ($debug === true) {
echo $updateString;
die();
} else {
$this->execute($updateString);
}
break;
}
}
function getBindVarValue($value, $type) {
$typeArray = explode(':',$type);
$type = $typeArray[0];
switch ($type) {
case 'csv':
return $value;
break;
case 'passthru':
return $value;
break;
case 'float':
return (!zen_not_null($value) || $value=='' || $value == 0) ? 0 : $value;
break;
case 'integer':
return (int)$value;
break;
case 'string':
if (isset($typeArray[1])) {
$regexp = $typeArray[1];
}
return '\'' . $this->prepare_input($value) . '\'';
break;
case 'noquotestring':
return $this->prepare_input($value);
break;
case 'currency':
return '\'' . $this->prepare_input($value) . '\'';
break;
case 'date':
return '\'' . $this->prepare_input($value) . '\'';
break;
case 'enum':
if (isset($typeArray[1])) {
$enumArray = explode('|', $typeArray[1]);
}
return '\'' . $this->prepare_input($value) . '\'';
case 'regexp':
$searchArray = array('[', ']', '(', ')', '{', '}', '|', '*', '?', '.', '$', '^');
foreach ($searchArray as $searchTerm) {
$value = str_replace($searchTerm, '\\' . $searchTerm, $value);
}
return $this->prepare_input($value);
default:
die('var-type undefined: ' . $type . '('.$value.')');
}
}
/**
* method to do bind variables to a query
**/
function bindVars($sql, $bindVarString, $bindVarValue, $bindVarType, $debug = false) {
$bindVarTypeArray = explode(':', $bindVarType);
$sqlNew = $this->getBindVarValue($bindVarValue, $bindVarType);
$sqlNew = str_replace($bindVarString, $sqlNew, $sql);
return $sqlNew;
}
function prepareInput($string) {
return @mysql_real_escape_string($string);
}
}
class queryFactoryResult {
function queryFactoryResult() {
$this->is_cached = false;
}
function MoveNext() {
global $zc_cache;
$this->cursor++;
if ($this->is_cached) {
if ($this->cursor >= sizeof($this->result)) {
$this->EOF = true;
} else {
while(list($key, $value) = each($this->result[$this->cursor])) {
$this->fields[$key] = $value;
}
}
} else {
$zp_result_array = @mysql_fetch_array($this->resource);
if (!$zp_result_array) {
$this->EOF = true;
} else {
while (list($key, $value) = each($zp_result_array)) {
if (!ereg('^[0-9]', $key)) {
$this->fields[$key] = $value;
}
}
}
}
}
function MoveNextRandom() {
$this->cursor++;
if ($this->cursor < $this->Limit) {
$zp_result_array = $this->result[$this->result_random[$this->cursor]];
while (list($key, $value) = each($zp_result_array)) {
if (!ereg('^[0-9]', $key)) {
$this->fields[$key] = $value;
}
}
} else {
$this->EOF = true;
}
}
function RecordCount() {
return @mysql_num_rows($this->resource);
}
function Move($zp_row) {
global $db;
if (@mysql_data_seek($this->resource, $zp_row)) {
$zp_result_array = @mysql_fetch_array($this->resource);
while (list($key, $value) = each($zp_result_array)) {
$this->fields[$key] = $value;
}
@mysql_data_seek($this->resource, $zp_row);
$this->EOF = false;
return;
} else {
$this->EOF = true;
$db->set_error(mysql_errno(),mysql_error());
}
}
}
class queryFactoryMeta {
function queryFactoryMeta($zp_field, $zp_res) {
$this->type = @mysql_field_type($zp_res, $zp_field);
$this->max_length = @mysql_field_len($zp_res, $zp_field);
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -