数据库语法
self::$db->table('Persons')->where(['sex'=>'m','id'=>array(1,2,4)])->getAll();
self::$db->table('Persons')->where(['sex'=>'m','id'=>array(1,2,4)],'efg,id')->getAll();
self::$db->table('Persons')->where(" and sex='m'",'efg,id')->getAll();
self::$db->table('Persons')->where(['id'=>7],'efg,sex')->orderBy('id', 'ASC')->getAll();
self::$db->table('Persons')->pageAll(['id'=>'7'],'id','ASC');
self::$db->getAll("SELECT efg,sex FROM ".self::$db->getTable('Persons')." where sex=7 ");
self::$db->table('Persons')->where(['id'=>7])->getRow();
self::$db->table('Persons')->where(['id'=>7],'*')->getRow();
self::$db->table('Persons')->where(['id'=>7],'efg,sex')->getRow();
self::$db->table('Persons')->where(" and id=7",'efg,sex')->getRow();
self::$db->table('Persons')->where(['id'=>7],'efg,sex')->orderBy('sex', 'ASC')->getRow();
self::$db->table('Persons')->first('id',7,'efg,sex');
self::$db->getRow("SELECT efg,sex FROM ".self::$db->getTable('Persons')." where id=7 ");
self::$db->table('Persons')->where(['id'=>7],'sex')->getOne();
self::$db->table('Persons')->where(" and id=7",'sex')->getOne();
self::$db->table('Persons')->where(['id'=>7],'sex')->orderBy('sex', 'ASC')->getOne();
self::$db->getOne("SELECT sex FROM ".self::$db->getTable('Persons')." where id=7 ");
$row_count = self::$db->table("Persons")->update(array('sex'=>'7'),'id=7');
// 等价于
$row_count = self::$db->query("UPDATE ".self::$db->backTable("Persons")." SET `sex` = 'F' WHERE id=7");
$insert_id = self::$db->table('Persons')->insert(array('Firstname'=>'abc','Lastname'=>'efg','Sex'=>'M','Age'=>13));
// 等价于
$insert_id = self::$db->query("INSERT INTO ".self::$db->backTable("Persons")." ( `Firstname`,`Lastname`,`Sex`,`Age`) VALUES ( 'abc', 'efg', 'M', 13)");
self::$db->table('Persons')->delete("name='{$name}'");
// 等价于
self::$db->query("DELETE FROM ".self::$db->backTable("Persons")." WHERE ID=9");
self::$db->table('Persons')->where(['sex'=>'m'],'id')->getCol();
// return array(1,2,3,4);
self::$db->table('Persons')->where(['sex'=>'m'],'id')->getCol('','cc');
// return array('1'=>'cc','2'=>'cc','3'=>'cc','4'=>'cc');
self::$db->table('Persons')->where(['sex'=>7])->toArray('id');
// return array(1,2,3,4);
// 获得所有数据
self::$db->table('Persons')->where(['id'=>7],'efg,sex')->orderBy('id', 'ASC')->limit(8,15)->getAll();
self::$db->table('Persons')->where(' and sex '.self::$db->db_create_in(['m','y']).' ','id')->getAll();
self::$db->table('Persons')->left('a.id',"id,Lastname",'left join '.self::$db->backTable('admin').' as b on a.Lastname = b.Lastname ')->pageAll(['id'=>'7'],'id','ASC');
// 数据表的总数
self::$db->table('Persons')->total();
// 等价于
self::$db->getOne("SELECT count(*) FROM ".self::$db->getTable('Persons'));
// 返回单列数组
self::$db->table('Persons')->where(['sex'=>7],'id,sex')->getColumn('id');
// return array('7'=>['id'=>7,'sex'=>'m'],'8'=>['id'=>8,'sex'=>'x']);
self::$db->table('Persons')->where(['sex'=>7],'id,sex')->getColumnOne('id','sex');
// return array('7'=>'m','8'=>'x');
// 参数默认值
$_REQUEST['limit'] = 10;
$_REQUEST['page'] = 1;
// 简单
self::$db->table('Persons')->pageList(['sex'=>'m'],'id','desc');
// 等价于
$db->table('Persons ')->left('*',"*")->pageList("sex ='7'",'id','desc');
// 常用
$db->table('Persons ')->left('*',"id,Lastname")->pageList("sex ='7'",'id','desc');
$db->table('Persons ')->left('*',"id,Lastname")->pageList(['sex'=>7],'id','desc');
self::$db->pageSql("SELECT count(*) FROM ".self::$db->getTable('Persons')." where sex='m'","SELECT id,Lastname FROM ".self::$db->getTable('Persons')." where sex='m'");
// 返回结果数据
return array("info"=>array(
array('id'=>1,'Lastname'=>'周'),
array('id'=>2,'Lastname'=>'李'),
....
),
'filter'=>array('page'=>1,'count'=>20,'page_count'=>2,'limit'=>10)
);
// 复杂
$db->table('Persons as a')->left('*',"id,Lastname",'left join '.self::$db->backTable('admin').' as b on a.name = b.name ')->pageList(['sex'=>7],'id','desc');
$db->table('Persons as a')->left('*',"id,Lastname",'left join '.self::$db->backTable('admin').' as b on a.Lastname = b.Lastname ')->pageList('sex=7 GROUP BY a.Lastname','id','desc',true);