Discuz!X3.1数据库的操作(一)
2017-09-09 16:28
330 查看
数据库指的是以一定方式储存在一起、能为多个用户共享、具有尽可能小的余度、与应用程序彼此独立的数据集合。产品中的主题,帖子,用户,关注等等。所有数据都存储在数据库中。
参数解释:
$table:插入数据的表
$data:插入的数据,字段对应值
$return_insert_id:是否返回插入数据的ID
$replace:是否使用replace into
$slient:操作失败是否不提示
参数解释:
$table:删除数据的表
$condition:删除条件
$limit:删除满足条件的目数
$unbuffered:是否使用无缓存查询
插入的值如果是变量用array()
参数解释:
$table:(更新数据的表)
$data:更新的数据,字段对应的
$condition:更新的条件
$unbuffrerd:是否使用无缓存查询
$low_priority:是否采用无损更新表
参数解释:
$sql:查询数据的sql语句
$arg:绑定查询的参数
$silent:查询失败时是否不提示
通过%n进行数据查询
参数解释:
$sql:查询数据的SQL语句
$arg:绑定查询的参数
$keyfield:一维索引的字段名称
$silent:查询失败的是否不提示
比较常用语统计查询
取最大值id
参数解释:
$sql:查询数据的sql语句
$arg:绑定查询的参数
$silent:查询失败时是否不提示
官方数据字典
http://faq.comsenz.com/library/database/x3/x3_index.htm数据库规范
http://dev.discuz.org/wiki/index.php?title=编码规范数据表插入操作
方法名:DB::insert()1 2 3 4 5 | <?php DB::insert('test_db',array( 'dname' => 'ppc', ),true); ?> |
$table:插入数据的表
$data:插入的数据,字段对应值
$return_insert_id:是否返回插入数据的ID
$replace:是否使用replace into
1 2 3 4 5 6 7 | <?php //$replace 当存在数据执行修改,不存在执行写入 DB::insert('test_db',array( 'did' => '1', 'dname' => 'ppc', ),true,true); ?> |
数据表删除操作
方法名:DB::delete()1 2 3 | <?php DB::delete('test_db','dId=4',1,true) ?> |
$table:删除数据的表
$condition:删除条件
$limit:删除满足条件的目数
$unbuffered:是否使用无缓存查询
数据表更新操作
方法名:DB::update()1 2 3 4 5 | <?php DB::update('test_db',array( 'dName' => 'ppc2' ),'dId=5',true); ?> |
1 | DB::update('borle_do',array('countMoney' => $countMoney),array('doId'=> $doId),true);} |
$table:(更新数据的表)
$data:更新的数据,字段对应的
$condition:更新的条件
$unbuffrerd:是否使用无缓存查询
$low_priority:是否采用无损更新表
绑定查询的参数解释
表达式 | 数据处理 |
%t | DB::table() |
%d | Intval() |
%s | addslashes |
%n | IN(1,2,3) |
%f | Sprintf(‘%f,%var’) |
%i | 不做任何处理 |
数据表查询操作(单条)
方法名:DB::fetch_first()1 2 3 4 5 6 7 | <?php $dId = 5;//可以使用$dId = '2admin',输出2,由于Intval()将指转换为2 $data = DB::fetch_first('select * from %t where dId=%d', array('test_db',$dId) ); print_r($data); ?> |
$sql:查询数据的sql语句
$arg:绑定查询的参数
$silent:查询失败时是否不提示
数据表查询操作(多条)
方法名:DB::fetch_all()1 2 3 4 5 6 7 8 | <?php $data = DB::fetch_all("select * from %t where dId>=%d and dId<=%d", array('test_db',1,9), 'dId' ); print_r($data); ?> |
1 2 3 4 5 6 7 | <?php //%n表示array(1,2,3,4,5,6) $data = DB::fetch_all("select * from %t where dId in (%n)", array('test_db',array(1,2,3,4,5,6)) ); print_r($data); ?> |
$sql:查询数据的SQL语句
$arg:绑定查询的参数
$keyfield:一维索引的字段名称
$silent:查询失败的是否不提示
数据表查询操作(单字段)
方法名:DB::result_first()1 2 3 4 5 6 7 | <?php //查询dName字段id=1的数据 $data = DB::result_first("select dName from %t where dId=%d", array('test_db',1) ); echo $data; ?> |
1 2 3 4 5 6 | <?php $data = DB::result_first("select count(*) from %t", array('test_db') ); echo $data; ?> |
1 2 3 4 5 6 | <?php $data = DB::result_first("select max(dId) from %t", array('test_db') ); echo $data; ?> |
$sql:查询数据的sql语句
$arg:绑定查询的参数
$silent:查询失败时是否不提示
相关文章推荐
- Discuz!X3.1数据库的操作(二)
- Discuz!X3.1数据库的操作(三)
- 数据操作__Discuz X2二次开发之数据库操作 DB类
- Discuz!X/数据库操作函数
- (菜鸟篇) 浅谈DISCUZ X系列 数据库的操作
- Discuz X2二次开发之数据库操作
- 数据库删除discuz 部分数据操作
- Discuz!数据库操作DB类和C::t类介绍
- discuz插件操作数据库实例
- discuz插件操作数据库实例
- Discuz!X3.1后台操作技巧(整合)
- Discuz!数据库操作DB类和C::t类介绍
- discuz X3.2 DB:类数据库操作
- discuz数据库操作,记录备用
- discuz学习笔记:以easyUI DataGrid为前台进行数据库增查删改操作
- Discuz!数据库操作DB类和C::t类介绍
- 如何读取配置文件并连接后台数据库,且对数据库进行操作实例(查询或修改等)
- Django-数据库操作
- 数据库-T-SQL 语句-创建表,删除表,CRUD操作的添加数据,修改数据,删除数据
- javaee 数据库操作DAO工厂设计模式