codecamp

查询

基本

尝试获取整表记录

$rows = $db->table_name();


//or 第二种写法


$rows = $db->table('table_name');


//如果在action中直接 return 得到标准的 json/xml 结构体


return $rows;

尝试根据主键获取指定记录

$row = $db->table_name($id);


//or 第二种写法


$row = $db->table('table_name',$id);


请注意,以上返回的是对象格式。如果需要数组格式?

$rows = $db->table_name()->fetchAll();


//or 第二种写法


$rows = $db->table('table_name')->fetchAll();


//主键获取指定记录


$row = $db->table_name($id)->fetch();


//or 第二种写法


$row = $db->table('table_name',$id)->fetch();

根据多维条件获取数据

//where 具体使用方法请在 API where() 文档中阅读 $rows = $db->table_name()->where($where)->fetchAll();


//whereNot 具体使用方法请在 API where() 文档中阅读
$rows = $db->table_name()->whereNot($whereNot)->fetchAll();


//limit 使用
$rows = $db->table_name()->where($where)->limit($count , $offset)->fetchAll();


//orderBy 使用
$rows = $db->table_name()->where($where)->orderBy('id','DESC')->fetch();


//fetch() 获取单条记录
$db->table_name()->fetch();


//fetchAll() 获取多条记录
$db->table_name()->fetchAll();


//select 使用
$db->table_name()->select('id')->where($where)->fetch();


//count 统计
$db->table_name()->count('id');


//min()
$db->table_name()->min('id');


//max()
$db->table_name()->max('id');


//sum
$db->table_name()->sum('num');

where or whereNot 多个连贯使用

//select * from table_name where id = $id and id != $id; $db->table_name()->where('id = ? ',$id)->whereNot('id',$id);

更多有趣的使用,或本文遗漏的写法。欢迎反馈至官方联系方式。

API
更新
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

应用

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }