|
|

关于(2),添加到class db中的方法
- //add function field to adjust discuz x3+
-
- public static function quote($str, $noarray = false) {
- if (is_string($str))
- return '\'' . self::mysqli_escape($str) . '\'';
- if (is_int($str) or is_float($str))
- return '\'' . $str . '\'';
- if (is_array($str)) {
- if($noarray === false) {
- foreach ($str as &$v) {
- $v = self::quote($v, true);
- }
- return $str;
- } else {
- return '\'\'';
- }
- }
- if (is_bool($str))
- return $str ? '1' : '0';
- return '\'\'';
- }
- public static function quote_field($field) {
- if (is_array($field)) {
- foreach ($field as $k => $v) {
- $field[$k] = self::quote_field($v);
- }
- } else {
- if (strpos($field, '`') !== false)
- $field = str_replace('`', '', $field);
- $field = '`' . $field . '`';
- }
- return $field;
- }
-
- public static function field($field, $val, $glue = '=') {
- $field = self::quote_field($field);
- if (is_array($val)) {
- $glue = $glue == 'notin' ? 'notin' : 'in';
- } elseif ($glue == 'in') {
- $glue = '=';
- }
- switch ($glue) {
- case '=':
- return $field . $glue . self::quote($val);
- break;
- case '-':
- case '+':
- return $field . '=' . $field . $glue . self::quote((string) $val);
- break;
- case '|':
- case '&':
- case '^':
- return $field . '=' . $field . $glue . self::quote($val);
- break;
- case '>':
- case '<':
- case '<>':
- case '<=':
- case '>=':
- return $field . $glue . self::quote($val);
- break;
- case 'like':
- return $field . ' LIKE(' . self::quote($val) . ')';
- break;
- case 'in':
- case 'notin':
- $val = $val ? implode(',', self::quote($val)) : '\'\'';
- return $field . ($glue == 'notin' ? ' NOT' : '') . ' IN(' . $val . ')';
- break;
- default:
- //throw new DbException('Not allow this glue between field and value: "' . $glue . '"');
- //fuck x3...
- exit('Not allow this glue between field and value: "');
- }
- }
-
- //discuz x3+ function area ends.
复制代码
|
|
|
|
|
|