
// 获取所有数据
\temmoku\db::select('ID,Sex')->from('Persons')->where('sex= :sex AND ID = :id')->bindValues(array('sex'=>'M', 'id' => 1))->query();
//等价于
\temmoku\db::select('ID,Sex')->from('Persons')->where("sex= 'M' AND ID = 1")->query();
//等价于
\temmoku\db::query("SELECT ID,Sex FROM `Persons` WHERE sex='M' AND ID = 1");


// 获取一行数据
\temmoku\db::select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->row();
//等价于
\temmoku\db::select('ID,Sex')->from('Persons')->where("sex= 'M' ")->row();
//等价于
\temmoku\db::row("SELECT ID,Sex FROM `Persons` WHERE sex='M'");


// 获取一列数据
\temmoku\db::select('ID')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->column();
//等价于
\temmoku\db::select('ID')->from('Persons')->where("sex= 'F' ")->column();
//等价于
\temmoku\db::column("SELECT `ID` FROM `Persons` WHERE sex='M'");

// 获取单个值
\temmoku\db::select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->single();
//等价于
\temmoku\db::select('ID,Sex')->from('Persons')->where("sex= 'F' ")->single();
//等价于
\temmoku\db::single("SELECT ID,Sex FROM `Persons` WHERE sex='M'");

// 复杂查询
\temmoku\db::select('*')->from('table1')->innerJoin('table2','table1.uid = table2.uid')->where('age > :age')->groupBy(array('aid'))->having('foo="foo"')->orderByASC/*orderByDESC*/(array('did'))
->limit(10)->offset(20)->bindValues(array('age' => 13));
// 等价于
\temmoku\db::query('SELECT * FROM `table1` INNER JOIN `table2` ON `table1`.`uid` = `table2`.`uid`
WHERE age > 13 GROUP BY aid HAVING foo="foo" ORDER BY did LIMIT 10 OFFSET 20');

// 插入
$insert_id = \temmoku\db::insert('Persons')->cols(array(
    'Firstname'=>'abc',
    'Lastname'=>'efg',
    'Sex'=>'M',
    'Age'=>13))->query();
等价于
$insert_id = \temmoku\db::query("INSERT INTO `Persons` ( `Firstname`,`Lastname`,`Sex`,`Age`)
VALUES ( 'abc', 'efg', 'M', 13)");

// 更新
$row_count = \temmoku\db::update('Persons')->cols(array('sex'))->where('ID=1')
->bindValue('sex', 'F')->query();
// 等价于
$row_count = \temmoku\db::update('Persons')->cols(array('sex'=>'F'))->where('ID=1')->query();
// 等价于
$row_count = \temmoku\db::query("UPDATE `Persons` SET `sex` = 'F' WHERE ID=1");

// 删除
$row_count = \temmoku\db::delete('Persons')->where('ID=9')->query();
// 等价于
$row_count = \temmoku\db::query("DELETE FROM `Persons` WHERE ID=9");

// 事务
\temmoku\db::beginTrans();
....
\temmoku\db::commitTrans(); // or \temmoku\db::rollBackTrans();

