<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: discuz_database.php 28779 2012-03-13 02:01:51Z cnteacher $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class discuz_database {
public static $db;
public static $driver;
public static function init($driver, $config) {
self::$driver = $driver;
self::$db = new $driver;
self::$db->set_config($config);
self::$db->connect();
}
public static function object() {
return self::$db;
}
public static function table($table) {
return self::$db->table_name($table);
}
public static function delete($table, $condition, $limit = 0, $unbuffered = true) {
if (empty($condition)) {
return false;
} elseif (is_array($condition)) {
if (count($condition) == 2 && isset($condition['where']) && isset($condition['arg'])) {
$where = self::format($condition['where'], $condition['arg']);
} else {
$where = self::implode_field_value($condition, ' AND ');
}
} else {
$where = $condition;
}
$limit = dintval($limit);
$sql = "DELETE FROM " . self::table($table) . " WHERE $where " . ($limit ? "LIMIT $limit" : '');
return self::query($sql, ($unbuffered ? 'UNBUFFERED' : ''));
}
public static function insert($table, $data, $return_insert_id = false, $replace = false, $silent = false) {
$sql = self::implode($data);
$cmd = $replace ? 'REPLACE INTO' : 'INSERT INTO';
$table = self::table($table);
$silent = $silent ? 'SILENT' : '';
return self::query("$cmd $table SET $sql", null, $silent, !$return_insert_id);
}
public static function update($table, $data, $condition, $unbuffered = false, $low_priority = false) {
$sql = self::implode($data);
if(empty($sql)) {
return false;
}
$cmd = "UPDATE " . ($low_priority ? 'LOW_PRIORITY' : '');
$table = self::table($table);
$where = '';
if (empty($condition)) {
$where = '1';
} elseif (is_array($condition)) {
$where = self::implode($condition, ' AND ');
} else {
$where = $condition;
}
$res = self::query("$cmd $table SET $sql WHERE $where", $unbuffered ? 'UNBUFFERED' : '');
return $res;
}
public static function insert_id() {
return self::$db->insert_id();
}
public static function fetch($resourceid, $type = MYSQL_ASSOC) {
return self::$db->fetch_array($resourceid, $type);
}
public static function fetch_first($sql, $arg = array(), $silent = false) {
$res = self::query($sql, $arg, $silent, false);
$ret = self::$db->fetch_array($res);
self::$db->free_result($res);
return $ret ? $ret : array();
}
public static function fetch_all($sql, $arg = array(), $keyfield = '', $silent=false) {
$data = array();
$query = self::query($sql, $arg, $silent, false);
while ($row = self::$db->fetch_array($query)) {
if ($keyfield && isset($row[$keyfield])) {
$data[$row[$keyfield]] = $row;
} else {
$data[] = $row;
}
}
self::$db->free_result($query);
return $data;
}
public static function result($resourceid, $row = 0) {
return self::$db->result($resourceid, $row);
}
public static function result_first($sql, $arg = array(), $silent = false) {
$res = self::query($sql, $arg, $silent, false);
$ret = self::$db->result($res, 0);
self::$db->free_result($res);
return $ret;
}
public static function query($sql, $arg = array(), $silent = false, $unbuffered = false) {
if (!empty($arg)) {
if (is_array($arg)) {
$sql = self::format($sql, $arg);
} elseif ($arg === 'SILENT') {
$silent = true;
} elseif ($arg === 'UNBUFFERED') {
$unbuffered = true;
}
}
self::checkquery($sql);
$ret = self::$db->query($sql, $silent, $unbuffered);
if (!$unbuffered && $ret) {
$cmd = trim(strtoupper(substr($sql, 0, strpos($sql, ' '))));
if ($cmd === 'SELECT') {
} elseif ($cmd === 'UPDATE' || $cmd === 'DELETE') {
$ret = self::$db->affected_rows();
} elseif ($cmd === 'INSERT') {
$ret = self::$db->insert_id();
}
}
return $ret;
}
public static function num_rows($resourceid) {
return self::$db->num_rows($resourceid);
}
public static function affected_rows() {
return self::$db->affected_rows();
}
public static function free_result($query) {
return self::$db->free_result($query);
}
public static function error() {
return self::$db->error();
}
public static function errno() {
return self::$db->errno();
}
public static function checkquery($sql) {
return discuz_database_safecheck::checkquery($sql);
}
public static function quote($str, $noarray = false) {
if (is_string($str))
return '\'' . addcslashes($str, "\n\r\\'\"\032") . '\'';
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 limit($start, $limit = 0) {
$limit = intval($limit > 0 ? $limit : 0);
$start = intval($start > 0 ? $start : 0);
if ($start && $limit) {
return " LIMIT $start, $limit";
} elseif ($limit) {
return " LIMIT $limit";
} elseif ($start) {
return " LIMIT $start";
} else {
return '';
}
}
public static function order($field, $order = 'ASC') {
if(empty($field)) {
return '';
}
$order = strtoupper($order) == 'ASC' || empty($order) ? 'ASC' : 'DESC';
return self::quote_field($field) . ' ' . $order;
}
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 . '"');
}
}
public static function implode($array, $glue = ',') {
$sql = $comma = '';
$glue = ' ' . trim($glue) . ' ';
foreach ($array as $k => $v) {
$sql .= $comma . self::quote_field($k) . '=' . self::quote($v);
$comma = $glue;
}
return $sql;
}
public static function implode_field_value($array, $glue = ',') {
return self::implode($array, $glue);
}
public static function format($sql, $arg) {
$count = substr_count($sql, '%');
if (!$count) {
return $sql;
} elseif ($count > count($arg)) {
throw new DbException('SQL string format error! This SQL need "' . $count . '" vars to replace into.', 0, $sql);
}
$len = strlen($sql);
$i = $find = 0;
$ret = '';
while ($i <= $len && $find < $count) {
if ($sql{$i} == '%') {
$next = $sql{$i + 1};
if ($next == 't') {
$ret .= self::table($arg[$fin
没有合适的资源?快使用搜索试试~ 我知道了~
discuzx3 tel114插件
共97个文件
php:47个
htm:22个
jpg:17个
3星 · 超过75%的资源 需积分: 9 9 下载量 103 浏览量
2013-06-13
15:49:03
上传
评论
收藏 262KB ZIP 举报
温馨提示
上传至BBS\source\plugin目录,网站前台运行,根据提示操作即可。
资源推荐
资源详情
资源评论
收起资源包目录
tel114_1.130.zip (97个子文件)
sanree_tel114
block
sanree
blockclass.php 101B
index.htm 0B
block_tel114.php 4KB
index.htm 0B
config.inc.php 1KB
validator.xml 8KB
admincp.inc.php 2KB
upgrade.php 5KB
condition
X3
base.php 246B
index.htm 0B
index.php 378B
X2.5 RC
base.php 246B
index.htm 0B
X2.5
base.php 246B
index.htm 0B
X2
discuz_table.php 7KB
discuz_base.php 1KB
base.php 2KB
discuz_database.php 11KB
index.htm 0B
index.htm 0B
Donation.inc.php 504B
buy.inc.php 461B
newfunction.inc.php 463B
module
sanree_tel114
sanree_tel114_error.php 1KB
sanree_tel114_telnumshowimg.php 612B
sanree_tel114_view.php 4KB
sanree_tel114_add.php 2KB
index.htm 0B
sanree_tel114_index.php 4KB
index.htm 0B
discuz_plugin_sanree_tel114_TC_UTF8.xml 29KB
discuz_plugin_sanree_tel114_SC_GBK.xml 27KB
install.php 5KB
discuz_plugin_sanree_tel114_SC_UTF8.xml 29KB
discuz_plugin_sanree_tel114_TC_BIG5.xml 27KB
template
view_ajax.htm 3KB
add.htm 3KB
error.htm 2KB
view.htm 3KB
index.htm 3KB
admincp
sanree_tel114
sanree_tel114_telnew.php 3KB
sanree_tel114_cateedit.php 1KB
sanree_tel114_error.php 3KB
sanree_tel114_teltop.php 690B
sanree_tel114_commondefault.php 539B
sanree_tel114_teltj.php 662B
sanree_tel114_teladdnew.php 4KB
sanree_tel114_teledit.php 5KB
sanree_tel114_cattj.php 606B
sanree_tel114_control.php 3KB
sanree_tel114_list.php 4KB
index.htm 0B
sanree_tel114_commontellist.php 3KB
sanree_tel114_telshen.php 712B
sanree_tel114_tellist.php 5KB
index.htm 0B
manage.inc.php 11KB
images
dj.jpg 17KB
towbg.jpg 3KB
viewbg1.jpg 8KB
quebtn.jpg 6KB
err.gif 1004B
sico.jpg 1KB
logo.jpg 3KB
addbg.jpg 8KB
star.jpg 1KB
onebg.jpg 14KB
searchbtn.jpg 3KB
ad.jpg 32KB
H2.jpg 10KB
share.jpg 10KB
ad3.gif 40KB
index.htm 0B
ge.gif 317B
h1.jpg 10KB
viewbg.jpg 8KB
shortbg.jpg 324B
tel114.jpg 27KB
js
tel114.js 44B
index.htm 0B
hoverie6.js 1012B
sanree_tel114.inc.php 2KB
index.htm 0B
uninstall.php 890B
style
tel.css 10KB
index.htm 0B
function
function_core.php 1KB
index.htm 0B
help.inc.php 446B
table
table_tel114_error.php 804B
table_tel114_tel.php 7KB
table_xcommon_member.php 1KB
table_tel114_common.php 2KB
index.htm 0B
table_tel114_category.php 1KB
无法安装正版提示解除文件
source
function
function_cloudaddons.php 11KB
共 97 条
- 1
资源评论
- 听风老祖2014-09-02新版用不了
- tianxue3103182014-10-03新版本x3.2用不了。
- monlone2014-01-21哎。没有想像中的好用。。。
- blackpens2013-10-04用起来还是不错的!
ahdzwsy
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功