boa框架开发手册v5.2

构造器查询

使用构造器来构造SQL语句,一定要以table()方法开始,以查询动作结束

查询动作

主要支持以下5个动作:

  • 增:insert()
  • 删:delete()
  • 改:update()
  • 查:select()
  • 查:find(),单条记录

$db = boa::db();
$data = ['title'=>'Title', 'content'=>'Content'];

$res = $db->table('news')->insert($data);
$res = $db->table('news')->where('id = ?', 1)->delete();
$res = $db->table('news')->where('id = ?', 1)->update($data);

$arr = $db->table('news A')
->field('A.*, B.category AS cat, COUNT(C.*) total')
->join('category B', 'A.cid = B.id')
->join('tag C', 'A.id = C.pid')
->where('A.cid = ? AND A.status = ?', 9, 1)
->limit(50, 10)
->order('A.sort ASC, A.id DESC')
->select();

$arr = $db->table('news')->where('id = ?', 1)->find();

查询属性

可以通过distinct()、field()等方法设置SQL相应属性

子查询


$db = boa::db();
$sql = $db->table('news')->field('id')->where('id < ?', 10)->getsql()->select();
$arr = $db->table('test')->where("pid IN ($sql)")->select();