发几个常用的sql语句方法-models 模型使用

八刀丁二
八刀丁二 这家伙很懒,还没有设置简介

0 人点赞了该文章 · 4464 浏览

models 目录创建一个 sql.php {{{ <?php if (!defined('IN_ANWSION')) { die; } class sql_class extends AWS_MODEL { public function add_sql($table,$array){ //添加数据 return $this->insert($bm,$array); } public function all_sql($table,$where = null,$order = null,$limit = null, $offset = 0){ //返回一个表的数据 $users_list = $this->fetch_all($table,$where,$order,$limit,$offset) ; return array_slice($users_list, 0, null); } public function get_sql_count($table,$where = null){ //返回查询影响行数 if($table==null){ return 0 ; } return $this->count($table,$where); } public function row_sql($table,$where){ //返回一行 (第一次出现的数据) return $this->fetch_row($table,$where); } public function update_sql($table,$array,$where){ //修改数据 return $this->update($table,$array,$where); } public function del_sql($table,$where){ //删除数据 return $this->delete($table, $where); } } ?> }}} app 文件里面就可以直接使用 {{{ $数据 = $this->model('sql')->方法名(相对参数); }}} 像数组的可以这样子 {{{ $array = arrat( 'name' => 'admin' ); $this->model('sql')->add_sql('user',$array); }}} 对于返回结果自行做些判断吧,这比较通用的,还有些我没用到就没写出来了,还有取最大值最小值。 可以看源码配置方法 自己做些模型方便自己, 系统文件 `` system/aws_model.inc.php`` sql一些配置文件。!希望对跟我一样小白的有些帮助!

发布于 2014-12-02 00:55

免责声明:

本文由 八刀丁二 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

lianghh
2014-12-03 13:00
这是一个测试评论
trumanwang
2014-12-02 09:46
收藏了,有时间玩一玩:)
Alu
2014-12-02 09:35
WeCenter 数据库操作类更详细的请看这个文件:system\aws_model.inc.php 所有的查询方法都在这里。