|
@@ -199,10 +199,12 @@ class dao {
|
|
* @return object|bool
|
|
* @return object|bool
|
|
*/
|
|
*/
|
|
private function connectByPDO($params) {
|
|
private function connectByPDO($params) {
|
|
- if (!isset($params->driver))
|
|
|
|
|
|
+ if (!isset($params->driver)) {
|
|
self::triggerError('no pdo driver defined, it should be mysql or sqlite', __FILE__, __LINE__, $exit = true);
|
|
self::triggerError('no pdo driver defined, it should be mysql or sqlite', __FILE__, __LINE__, $exit = true);
|
|
- if (!isset($params->user))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!isset($params->user)) {
|
|
return false;
|
|
return false;
|
|
|
|
+ }
|
|
if ($params->driver == 'mysql') {
|
|
if ($params->driver == 'mysql') {
|
|
$dsn = "mysql:host={$params->host}; port={$params->port}; dbname={$params->name}";
|
|
$dsn = "mysql:host={$params->host}; port={$params->port}; dbname={$params->name}";
|
|
}
|
|
}
|
|
@@ -211,19 +213,24 @@ class dao {
|
|
$dbh->exec("SET NAMES {$params->encoding}");
|
|
$dbh->exec("SET NAMES {$params->encoding}");
|
|
|
|
|
|
/* If run on linux, set emulatePrepare and bufferQuery to true. */
|
|
/* If run on linux, set emulatePrepare and bufferQuery to true. */
|
|
- if (!isset($params->emulatePrepare) and PHP_OS == 'Linux')
|
|
|
|
|
|
+ if (!isset($params->emulatePrepare) and PHP_OS == 'Linux') {
|
|
$params->emulatePrepare = true;
|
|
$params->emulatePrepare = true;
|
|
- if (!isset($params->bufferQuery) and PHP_OS == 'Linux')
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!isset($params->bufferQuery) and PHP_OS == 'Linux') {
|
|
$params->bufferQuery = true;
|
|
$params->bufferQuery = true;
|
|
|
|
+ }
|
|
|
|
|
|
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
|
|
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
|
|
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
- if (isset($params->strictMode) and $params->strictMode == false)
|
|
|
|
|
|
+ if (isset($params->strictMode) and $params->strictMode == false) {
|
|
$dbh->exec("SET @@sql_mode= ''");
|
|
$dbh->exec("SET @@sql_mode= ''");
|
|
- if (isset($params->emulatePrepare))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (isset($params->emulatePrepare)) {
|
|
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, $params->emulatePrepare);
|
|
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, $params->emulatePrepare);
|
|
- if (isset($params->bufferQuery))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (isset($params->bufferQuery)) {
|
|
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $params->bufferQuery);
|
|
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $params->bufferQuery);
|
|
|
|
+ }
|
|
|
|
|
|
return $dbh;
|
|
return $dbh;
|
|
} catch (PDOException $exception) {
|
|
} catch (PDOException $exception) {
|
|
@@ -333,10 +340,12 @@ class dao {
|
|
$subLength = strlen($sql);
|
|
$subLength = strlen($sql);
|
|
$orderPOS = strripos($sql, DAO::ORDERBY);
|
|
$orderPOS = strripos($sql, DAO::ORDERBY);
|
|
$limitPOS = strripos($sql, DAO::LIMIT);
|
|
$limitPOS = strripos($sql, DAO::LIMIT);
|
|
- if ($limitPOS)
|
|
|
|
|
|
+ if ($limitPOS) {
|
|
$subLength = $limitPOS;
|
|
$subLength = $limitPOS;
|
|
- if ($orderPOS)
|
|
|
|
|
|
+ }
|
|
|
|
+ if ($orderPOS) {
|
|
$subLength = $orderPOS;
|
|
$subLength = $orderPOS;
|
|
|
|
+ }
|
|
$sql = substr($sql, 0, $subLength);
|
|
$sql = substr($sql, 0, $subLength);
|
|
self::$querys[] = $sql;
|
|
self::$querys[] = $sql;
|
|
|
|
|
|
@@ -421,8 +430,9 @@ class dao {
|
|
*/
|
|
*/
|
|
public function from($table) {
|
|
public function from($table) {
|
|
$this->setTable($table);
|
|
$this->setTable($table);
|
|
- if ($this->mode == 'raw')
|
|
|
|
|
|
+ if ($this->mode == 'raw') {
|
|
$this->sqlobj->from($table);
|
|
$this->sqlobj->from($table);
|
|
|
|
+ }
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -446,8 +456,9 @@ class dao {
|
|
* @return object the dao object self.
|
|
* @return object the dao object self.
|
|
*/
|
|
*/
|
|
public function alias($alias) {
|
|
public function alias($alias) {
|
|
- if (empty($this->alias))
|
|
|
|
|
|
+ if (empty($this->alias)) {
|
|
$this->setAlias($alias);
|
|
$this->setAlias($alias);
|
|
|
|
+ }
|
|
$this->sqlobj->alias($alias);
|
|
$this->sqlobj->alias($alias);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -460,8 +471,9 @@ class dao {
|
|
* @return object the dao object self.
|
|
* @return object the dao object self.
|
|
*/
|
|
*/
|
|
public function data($data) {
|
|
public function data($data) {
|
|
- if (!is_object($data))
|
|
|
|
|
|
+ if (!is_object($data)) {
|
|
$data = (object) $data;
|
|
$data = (object) $data;
|
|
|
|
+ }
|
|
$this->sqlobj->data($data);
|
|
$this->sqlobj->data($data);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -499,10 +511,12 @@ class dao {
|
|
|
|
|
|
/* If the mode is magic, process the $fields and $table. */
|
|
/* If the mode is magic, process the $fields and $table. */
|
|
if ($this->mode == 'magic') {
|
|
if ($this->mode == 'magic') {
|
|
- if ($this->fields == '')
|
|
|
|
|
|
+ if ($this->fields == '') {
|
|
$this->fields = '*';
|
|
$this->fields = '*';
|
|
- if ($this->table == '')
|
|
|
|
|
|
+ }
|
|
|
|
+ if ($this->table == '') {
|
|
$this->triggerError('Must set the table name', __FILE__, __LINE__, $exit = true);
|
|
$this->triggerError('Must set the table name', __FILE__, __LINE__, $exit = true);
|
|
|
|
+ }
|
|
$sql = sprintf($this->sqlobj->get(), $this->fields, $this->table);
|
|
$sql = sprintf($this->sqlobj->get(), $this->fields, $this->table);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -522,11 +536,10 @@ class dao {
|
|
*/
|
|
*/
|
|
private function triggerError($message, $file, $line, $exit = false) {
|
|
private function triggerError($message, $file, $line, $exit = false) {
|
|
/* Set the error info. */
|
|
/* Set the error info. */
|
|
- $log = "ERROR: " . CommUtil::str2UTF8($message) . " in "
|
|
|
|
- . CommUtil::str2UTF8($file) . " on line $line";
|
|
|
|
- if (isset($_SERVER['SCRIPT_URI']))
|
|
|
|
|
|
+ $log = "ERROR: " . CommUtil::str2UTF8($message) . " in " . CommUtil::str2UTF8($file) . " on line $line";
|
|
|
|
+ if (isset($_SERVER['SCRIPT_URI'])) {
|
|
$log .= ", request: $_SERVER[SCRIPT_URI]";
|
|
$log .= ", request: $_SERVER[SCRIPT_URI]";
|
|
- ;
|
|
|
|
|
|
+ }
|
|
$trace = debug_backtrace();
|
|
$trace = debug_backtrace();
|
|
extract($trace[0]); # function
|
|
extract($trace[0]); # function
|
|
extract($trace[1]); # line
|
|
extract($trace[1]); # line
|
|
@@ -607,8 +620,9 @@ class dao {
|
|
* @return object the dao object self.
|
|
* @return object the dao object self.
|
|
*/
|
|
*/
|
|
public function page($pager) {
|
|
public function page($pager) {
|
|
- if (!is_object($pager))
|
|
|
|
|
|
+ if (!is_object($pager)) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
|
|
|
|
/* If the record total is 0, compute it. */
|
|
/* If the record total is 0, compute it. */
|
|
if ($pager->recTotal == 0) {
|
|
if ($pager->recTotal == 0) {
|
|
@@ -623,10 +637,12 @@ class dao {
|
|
$subLength = strlen($sql);
|
|
$subLength = strlen($sql);
|
|
$orderPOS = strripos($sql, 'order ');
|
|
$orderPOS = strripos($sql, 'order ');
|
|
$limitPOS = strripos($sql, 'limit');
|
|
$limitPOS = strripos($sql, 'limit');
|
|
- if ($limitPOS)
|
|
|
|
|
|
+ if ($limitPOS) {
|
|
$subLength = $limitPOS;
|
|
$subLength = $limitPOS;
|
|
- if ($orderPOS)
|
|
|
|
|
|
+ }
|
|
|
|
+ if ($orderPOS) {
|
|
$subLength = $orderPOS;
|
|
$subLength = $orderPOS;
|
|
|
|
+ }
|
|
$sql = substr($sql, 0, $subLength);
|
|
$sql = substr($sql, 0, $subLength);
|
|
self::$querys[] = $sql;
|
|
self::$querys[] = $sql;
|
|
|
|
|
|
@@ -662,8 +678,9 @@ class dao {
|
|
* @return int the modified or deleted records.
|
|
* @return int the modified or deleted records.
|
|
*/
|
|
*/
|
|
public function exec($sql = '') {
|
|
public function exec($sql = '') {
|
|
- if (!empty(dao::$errors))
|
|
|
|
|
|
+ if (!empty(dao::$errors)) {
|
|
return new PDOStatement(); // If any error, return an empty statement object to make sure the remain method to execute.
|
|
return new PDOStatement(); // If any error, return an empty statement object to make sure the remain method to execute.
|
|
|
|
+ }
|
|
if ($sql) {
|
|
if ($sql) {
|
|
if (is_null($this->sqlobj)) {
|
|
if (is_null($this->sqlobj)) {
|
|
$this->sqlobj = sql::factory();
|
|
$this->sqlobj = sql::factory();
|
|
@@ -691,12 +708,15 @@ class dao {
|
|
* @return object|mixed
|
|
* @return object|mixed
|
|
*/
|
|
*/
|
|
public function fetch($field = '') {
|
|
public function fetch($field = '') {
|
|
- if (empty($field))
|
|
|
|
|
|
+ if (empty($field)) {
|
|
return $this->query()->fetch();
|
|
return $this->query()->fetch();
|
|
|
|
+ }
|
|
$this->setFields($field);
|
|
$this->setFields($field);
|
|
$result = $this->query()->fetch(PDO::FETCH_OBJ);
|
|
$result = $this->query()->fetch(PDO::FETCH_OBJ);
|
|
- if ($result)
|
|
|
|
|
|
+ if ($result) {
|
|
return $result->$field;
|
|
return $result->$field;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -710,11 +730,13 @@ class dao {
|
|
|
|
|
|
$stmt = $this->query();
|
|
$stmt = $this->query();
|
|
|
|
|
|
- if (empty($keyField))
|
|
|
|
|
|
+ if (empty($keyField)) {
|
|
return $stmt->fetchAll();
|
|
return $stmt->fetchAll();
|
|
|
|
+ }
|
|
$rows = array();
|
|
$rows = array();
|
|
- while ($row = $stmt->fetch())
|
|
|
|
|
|
+ while ($row = $stmt->fetch()) {
|
|
$rows[$row->$keyField] = $row;
|
|
$rows[$row->$keyField] = $row;
|
|
|
|
+ }
|
|
return $rows;
|
|
return $rows;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -751,8 +773,9 @@ class dao {
|
|
$stmt = $this->query();
|
|
$stmt = $this->query();
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
if (!$ready) {
|
|
if (!$ready) {
|
|
- if (empty($keyField))
|
|
|
|
|
|
+ if (empty($keyField)) {
|
|
$keyField = key($row);
|
|
$keyField = key($row);
|
|
|
|
+ }
|
|
if (empty($valueField)) {
|
|
if (empty($valueField)) {
|
|
end($row);
|
|
end($row);
|
|
$valueField = key($row);
|
|
$valueField = key($row);
|
|
@@ -812,8 +835,9 @@ class dao {
|
|
while ($row = $stmt->fetch()) {
|
|
while ($row = $stmt->fetch()) {
|
|
$key ? $rows[$row->$key] = $row : $rows[] = $row;
|
|
$key ? $rows[$row->$key] = $row : $rows[] = $row;
|
|
$i++;
|
|
$i++;
|
|
- if ($i == $max)
|
|
|
|
|
|
+ if ($i == $max) {
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return $rows;
|
|
return $rows;
|
|
}
|
|
}
|
|
@@ -839,9 +863,9 @@ class dao {
|
|
*/
|
|
*/
|
|
public function check($fieldName, $funcName) {
|
|
public function check($fieldName, $funcName) {
|
|
/* If no this field in the data, reuturn. */
|
|
/* If no this field in the data, reuturn. */
|
|
- if (!isset($this->sqlobj->data->$fieldName))
|
|
|
|
|
|
+ if (!isset($this->sqlobj->data->$fieldName)) {
|
|
return $this;
|
|
return $this;
|
|
-
|
|
|
|
|
|
+ }
|
|
/* Set the field label and value. */
|
|
/* Set the field label and value. */
|
|
global $lang, $config, $app;
|
|
global $lang, $config, $app;
|
|
$table = strtolower(str_replace(array($config->db->prefix, '`'), '', $this->table));
|
|
$table = strtolower(str_replace(array($config->db->prefix, '`'), '', $this->table));
|
|
@@ -852,12 +876,14 @@ class dao {
|
|
if ($funcName == 'unique') {
|
|
if ($funcName == 'unique') {
|
|
$args = func_get_args();
|
|
$args = func_get_args();
|
|
$sql = "SELECT COUNT(*) AS count FROM $this->table WHERE `$fieldName` = " . $this->sqlobj->quote($value);
|
|
$sql = "SELECT COUNT(*) AS count FROM $this->table WHERE `$fieldName` = " . $this->sqlobj->quote($value);
|
|
- if (isset($args[2]))
|
|
|
|
|
|
+ if (isset($args[2])) {
|
|
$sql .= ' AND ' . $args[2];
|
|
$sql .= ' AND ' . $args[2];
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
$row = $this->dbh->query($sql)->fetch();
|
|
$row = $this->dbh->query($sql)->fetch();
|
|
- if ($row->count != 0)
|
|
|
|
|
|
+ if ($row->count != 0) {
|
|
$this->logError($funcName, $fieldName, $fieldLabel, array($value));
|
|
$this->logError($funcName, $fieldName, $fieldLabel, array($value));
|
|
|
|
+ }
|
|
} catch (PDOException $e) {
|
|
} catch (PDOException $e) {
|
|
$this->sqlError($e);
|
|
$this->sqlError($e);
|
|
}
|
|
}
|
|
@@ -889,8 +915,9 @@ class dao {
|
|
* @return object the dao object self.
|
|
* @return object the dao object self.
|
|
*/
|
|
*/
|
|
public function checkIF($condition, $fieldName, $funcName) {
|
|
public function checkIF($condition, $fieldName, $funcName) {
|
|
- if (!$condition)
|
|
|
|
|
|
+ if (!$condition) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$funcArgs = func_get_args();
|
|
$funcArgs = func_get_args();
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
${"arg$i"} = isset($funcArgs[$i + 3]) ? $funcArgs[$i + 3] : null;
|
|
${"arg$i"} = isset($funcArgs[$i + 3]) ? $funcArgs[$i + 3] : null;
|
|
@@ -913,8 +940,9 @@ class dao {
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
|
|
${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
|
|
}
|
|
}
|
|
- foreach ($fields as $fieldName)
|
|
|
|
|
|
+ foreach ($fields as $fieldName) {
|
|
$this->check($fieldName, $funcName, $arg0, $arg1, $arg2);
|
|
$this->check($fieldName, $funcName, $arg0, $arg1, $arg2);
|
|
|
|
+ }
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -928,15 +956,17 @@ class dao {
|
|
* @return object the dao object self.
|
|
* @return object the dao object self.
|
|
*/
|
|
*/
|
|
public function batchCheckIF($condition, $fields, $funcName) {
|
|
public function batchCheckIF($condition, $fields, $funcName) {
|
|
- if (!$condition)
|
|
|
|
|
|
+ if (!$condition) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$fields = explode(',', str_replace(' ', '', $fields));
|
|
$fields = explode(',', str_replace(' ', '', $fields));
|
|
$funcArgs = func_get_args();
|
|
$funcArgs = func_get_args();
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
|
|
${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
|
|
}
|
|
}
|
|
- foreach ($fields as $fieldName)
|
|
|
|
|
|
+ foreach ($fields as $fieldName) {
|
|
$this->check($fieldName, $funcName, $arg0, $arg1, $arg2);
|
|
$this->check($fieldName, $funcName, $arg0, $arg1, $arg2);
|
|
|
|
+ }
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -952,15 +982,19 @@ class dao {
|
|
$skipFields = ",$skipFields,";
|
|
$skipFields = ",$skipFields,";
|
|
|
|
|
|
foreach ($fields as $fieldName => $validater) {
|
|
foreach ($fields as $fieldName => $validater) {
|
|
- if (strpos($skipFields, $fieldName) !== false)
|
|
|
|
|
|
+ if (strpos($skipFields, $fieldName) !== false) {
|
|
continue; // skip it.
|
|
continue; // skip it.
|
|
- if (!isset($this->sqlobj->data->$fieldName))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!isset($this->sqlobj->data->$fieldName)) {
|
|
continue;
|
|
continue;
|
|
- if ($validater['rule'] == 'skip')
|
|
|
|
|
|
+ }
|
|
|
|
+ if ($validater['rule'] == 'skip') {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
$options = array();
|
|
$options = array();
|
|
- if (isset($validater['options']))
|
|
|
|
|
|
+ if (isset($validater['options'])) {
|
|
$options = array_values($validater['options']);
|
|
$options = array_values($validater['options']);
|
|
|
|
+ }
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
|
|
${"arg$i"} = isset($options[$i]) ? $options[$i] : null;
|
|
${"arg$i"} = isset($options[$i]) ? $options[$i] : null;
|
|
}
|
|
}
|
|
@@ -990,7 +1024,7 @@ class dao {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
|
- return $ret !== FALSE; # false代表表不存在
|
|
|
|
|
|
+ return $ret !== FALSE; # false代表表不存在
|
|
}
|
|
}
|
|
|
|
|
|
public function Ping() {
|
|
public function Ping() {
|
|
@@ -1025,16 +1059,18 @@ class dao {
|
|
if (!is_array($error)) {
|
|
if (!is_array($error)) {
|
|
foreach ($replaces as $replace) {
|
|
foreach ($replaces as $replace) {
|
|
$pos = strpos($error, '%s');
|
|
$pos = strpos($error, '%s');
|
|
- if ($pos === false)
|
|
|
|
|
|
+ if ($pos === false) {
|
|
break;
|
|
break;
|
|
|
|
+ }
|
|
$error = substr($error, 0, $pos) . $replace . substr($error, $pos + 2);
|
|
$error = substr($error, 0, $pos) . $replace . substr($error, $pos + 2);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- /* If the error define is an array, select the one which %s counts match the $replaces. */ else {
|
|
|
|
|
|
+ } else {/* If the error define is an array, select the one which %s counts match the $replaces. */
|
|
/* Remove the empty items. */
|
|
/* Remove the empty items. */
|
|
- foreach ($replaces as $key => $value)
|
|
|
|
- if (is_null($value))
|
|
|
|
|
|
+ foreach ($replaces as $key => $value) {
|
|
|
|
+ if (is_null($value)) {
|
|
unset($replaces[$key]);
|
|
unset($replaces[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
$replacesCount = count($replaces);
|
|
$replacesCount = count($replaces);
|
|
foreach ($error as $errorString) {
|
|
foreach ($error as $errorString) {
|
|
if (substr_count($errorString, '%s') == $replacesCount) {
|
|
if (substr_count($errorString, '%s') == $replacesCount) {
|
|
@@ -1064,11 +1100,11 @@ class dao {
|
|
*/
|
|
*/
|
|
public static function getError($join = false) {
|
|
public static function getError($join = false) {
|
|
$errors = dao::$errors;
|
|
$errors = dao::$errors;
|
|
- dao::$errors = array(); // Must clear it.
|
|
|
|
|
|
+ dao::$errors = array(); # Must clear it.
|
|
|
|
|
|
- if (!$join)
|
|
|
|
|
|
+ if (!$join) {
|
|
return $errors;
|
|
return $errors;
|
|
-
|
|
|
|
|
|
+ }
|
|
if (is_array($errors)) {
|
|
if (is_array($errors)) {
|
|
$message = '';
|
|
$message = '';
|
|
foreach ($errors as $item) {
|
|
foreach ($errors as $item) {
|
|
@@ -1453,8 +1489,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function where($arg1, $arg2 = null, $arg3 = null) {
|
|
public function where($arg1, $arg2 = null, $arg3 = null) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
if ($arg3 !== null) {
|
|
if ($arg3 !== null) {
|
|
$value = $this->quote($arg3);
|
|
$value = $this->quote($arg3);
|
|
$condition = "`$arg1` $arg2 " . $this->quote($arg3);
|
|
$condition = "`$arg1` $arg2 " . $this->quote($arg3);
|
|
@@ -1474,8 +1511,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function andWhere($condition) {
|
|
public function andWhere($condition) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " AND $condition ";
|
|
$this->sql .= " AND $condition ";
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1488,8 +1526,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function orWhere($condition) {
|
|
public function orWhere($condition) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " OR $condition ";
|
|
$this->sql .= " OR $condition ";
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1502,8 +1541,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function eq($value) {
|
|
public function eq($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " = " . $this->quote($value);
|
|
$this->sql .= " = " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1516,8 +1556,9 @@ class sql {
|
|
* @return void the sql object.
|
|
* @return void the sql object.
|
|
*/
|
|
*/
|
|
public function ne($value) {
|
|
public function ne($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " != " . $this->quote($value);
|
|
$this->sql .= " != " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1530,8 +1571,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function gt($value) {
|
|
public function gt($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " > " . $this->quote($value);
|
|
$this->sql .= " > " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1544,8 +1586,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function ge($value) {
|
|
public function ge($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " >= " . $this->quote($value);
|
|
$this->sql .= " >= " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1558,8 +1601,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function lt($value) {
|
|
public function lt($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " < " . $this->quote($value);
|
|
$this->sql .= " < " . $this->quote($value);
|
|
|
|
|
|
return $this;
|
|
return $this;
|
|
@@ -1589,8 +1633,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function between($min, $max) {
|
|
public function between($min, $max) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$min = $this->quote($min);
|
|
$min = $this->quote($min);
|
|
$max = $this->quote($max);
|
|
$max = $this->quote($max);
|
|
$this->sql .= " BETWEEN $min AND $max ";
|
|
$this->sql .= " BETWEEN $min AND $max ";
|
|
@@ -1606,8 +1651,9 @@ class sql {
|
|
*/
|
|
*/
|
|
public function in($ids) {
|
|
public function in($ids) {
|
|
// var_dump($ids);
|
|
// var_dump($ids);
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= self::dbIN($ids);
|
|
$this->sql .= self::dbIN($ids);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1621,8 +1667,9 @@ class sql {
|
|
* @return string the string like IN('a', 'b').
|
|
* @return string the string like IN('a', 'b').
|
|
*/
|
|
*/
|
|
private static function dbIN($ids) {
|
|
private static function dbIN($ids) {
|
|
- if (is_array($ids))
|
|
|
|
|
|
+ if (is_array($ids)) {
|
|
return "IN ('" . join("','", $ids) . "')";
|
|
return "IN ('" . join("','", $ids) . "')";
|
|
|
|
+ }
|
|
return "IN ('" . str_replace(',', "','", str_replace(' ', '', $ids)) . "')";
|
|
return "IN ('" . str_replace(',', "','", str_replace(' ', '', $ids)) . "')";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1634,8 +1681,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function notin($ids) {
|
|
public function notin($ids) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= ' NOT ' . self::dbIN($ids);
|
|
$this->sql .= ' NOT ' . self::dbIN($ids);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1648,8 +1696,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function like($string) {
|
|
public function like($string) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= " LIKE " . $this->quote($string);
|
|
$this->sql .= " LIKE " . $this->quote($string);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1662,8 +1711,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function notLike($string) {
|
|
public function notLike($string) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= "NOT LIKE " . $this->quote($string);
|
|
$this->sql .= "NOT LIKE " . $this->quote($string);
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1677,8 +1727,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function findInSet($str, $strList) {
|
|
public function findInSet($str, $strList) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
$this->sql .= "FIND_IN_SET(" . $str . "," . $strList . ")";
|
|
$this->sql .= "FIND_IN_SET(" . $str . "," . $strList . ")";
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1690,8 +1741,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function orderBy($order) {
|
|
public function orderBy($order) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and!$this->conditionIsTrue) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
|
|
|
|
$order = str_replace(array('|', '', '_'), ' ', $order);
|
|
$order = str_replace(array('|', '', '_'), ' ', $order);
|
|
|
|
|
|
@@ -1706,13 +1758,17 @@ class sql {
|
|
$orderParse = explode(' ', trim($order));
|
|
$orderParse = explode(' ', trim($order));
|
|
foreach ($orderParse as $key => $value) {
|
|
foreach ($orderParse as $key => $value) {
|
|
$value = trim($value);
|
|
$value = trim($value);
|
|
- if (empty($value) or strtolower($value) == 'desc' or strtolower($value) == 'asc')
|
|
|
|
|
|
+ if (empty($value) #
|
|
|
|
+ or strtolower($value) == 'desc' #
|
|
|
|
+ or strtolower($value) == 'asc') {
|
|
continue;
|
|
continue;
|
|
|
|
+ }
|
|
$field = trim($value, '`');
|
|
$field = trim($value, '`');
|
|
|
|
|
|
/* such as t1.id field. */
|
|
/* such as t1.id field. */
|
|
- if (strpos($value, '.') !== false)
|
|
|
|
|
|
+ if (strpos($value, '.') !== false) {
|
|
list($table, $field) = explode('.', $field);
|
|
list($table, $field) = explode('.', $field);
|
|
|
|
+ }
|
|
$field = "`$field`";
|
|
$field = "`$field`";
|
|
|
|
|
|
$orderParse[$key] = isset($table) ? $table . '.' . $field : $field;
|
|
$orderParse[$key] = isset($table) ? $table . '.' . $field : $field;
|
|
@@ -1734,8 +1790,9 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function limit($limit) {
|
|
public function limit($limit) {
|
|
- if (empty($limit))
|
|
|
|
|
|
+ if (empty($limit)) {
|
|
return $this;
|
|
return $this;
|
|
|
|
+ }
|
|
stripos($limit, 'limit') !== false ? $this->sql .= " $limit " : $this->sql .= ' ' . DAO::LIMIT . " $limit ";
|
|
stripos($limit, 'limit') !== false ? $this->sql .= " $limit " : $this->sql .= ' ' . DAO::LIMIT . " $limit ";
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
@@ -1782,8 +1839,9 @@ class sql {
|
|
* @return mixed
|
|
* @return mixed
|
|
*/
|
|
*/
|
|
public function quote($value) {
|
|
public function quote($value) {
|
|
- if ($this->magicQuote)
|
|
|
|
|
|
+ if ($this->magicQuote) {
|
|
$value = stripslashes($value);
|
|
$value = stripslashes($value);
|
|
|
|
+ }
|
|
return $this->dbh->quote($value);
|
|
return $this->dbh->quote($value);
|
|
}
|
|
}
|
|
|
|
|