discuz 方法
写日志方法
runlog()
SQL 语句 format 的支持
表达式 | 数据处理 |
---|---|
%t | DB::table() |
%d | intval() |
%s | addslashes |
%n | in(1,2,3) |
%f | sprintf('%f',$var) |
%i | 不做任何处理 |
方法名:
DB::insert()
参数解释:
- $table:插入数据的表
- $data:插入的数据,字段对应值
- $return_insert_id:是否返回插入数据的ID
- $replace:是否使用replace into,当表中存在不能重复的数据,replace into 就相当于 更新
- $silent:操作失败是否不提示
例子:
DB::insert('test_db',array('name'=>'张三'),true);
方法名:
DB::delete()
参数解释:
- $table:删除数据的表
- $condition:删除条件
- $limit: 删除满足条件的条目数
- $unbuffered:是否使用无缓存查询
例子:
DB::delete('test_db','id > 5',2);
方法名:
DB::update()
参数解释:
- $table:更新数据的表
- $data:更新的数据,字段对应值
- $condition:更新条件
- $unbuffered:是否使用无缓存查询
- $low_priority:是否采用无锁表更新
例子:
DB::update('test_db',array('name'=>'lisi'),'id=4');
方法名:
DB::fetch_first()
参数解释:
- $sql:查询数据的SQL语句
- $ary:绑定查询的参数
- $silent:查询失败是否不提示
例子:
DB::fetch_first('SELECT * FROM %t where id > %d', array('test_db',$id) );
方法名:
DB::fetch_all()
参数解释:
- 获取全部
- $sql:查询数据的SQL语句
- $ary:绑定查询的参数
- $keyfield:一维索引的字段名称,把查询出来的ID的值当作一维索引
- $silent:查询失败时是否不提示
例子:
$data = DB::fetch_all('SELECT * FROM %t where id > %d',array('test_db',$id),'id');
方法名:
DB::result_first()
参数解释:
- 获取单行
- $sql:查询数据的SQL语句
- $ary:绑定查询的参数
- $silent:查询失败是否不提示
例子:
$data = DB::result_first('SELECT * FROM %t where id > %d',array('test_db',$id));
方法名:
DB::query()
参数解释:
- $sql:自定义SQL语句
- $ary:绑定查询的参数
- $silent:查询失败是否不提示
- $unbuffered:是否使用无缓存查询
例子:
$data = DB::query('SELECT * FROM %t where id > %d',array('test_db',$id));
方法名:
DB::num_rows()
参数解释:
- 获取行数
- $resourceid:资源
- $row:指定行的第一个字段
例子:
$data = DB::num_rows($res);
方法名:
DB::free_result()
参数解释:
- 释放资源
- $resourceid:资源
例子:
$data = DB::free_result($res);
方法名:
DB:: order()
参数解释:
- 排序
- $field:排序的字段
- $type:正序,倒序
例子:
$data = DB:: order('id','asc');
方法名:
DB::limit()
参数解释:
- 取值区间设定
- $start:开始的索引值
- $limit:条目数
例子:
$data = DB::limit('8','5');
方法名:
DB::implode==()==
参数解释:
- 字段拼接
- $array:需要拼接的字符数组
- $glue: 字段拼接的字符串
例子:
$data = DB::implode('8',',');
方法名:
DB::field()
参数解释:
- 字段数据设定
- $field:需要处理的字段名称
- $val: 字段对应的值
- $glue: 连接字段与值的类型
网友评论