成功返回 Object , 失败时返回 false
<?php // [SQL] SELECT * FROM `test` a RIGHT JOIN `image` b ON a.id = b.id HAVING b.id > ? [BVALUES] 100 $select = new Asf_Db_QueryBuilder_Select(); $select ->cols() ->from('test', 'a') ->rightJoin('image', 'b') ->on('a.id', 'b.id') ->having('b.id', 100, '>');
<?php // [SQL] SELECT * FROM `test` WHERE `pid` IN (?,?) OR `cid` IN (?,?) [BVALUES] 100 , 200 , 10 , 20 $select = new Asf_Db_QueryBuilder_Select(); $select ->cols() ->from('test') ->whereIn('pid', array('100', 200)) ->orWhereIn('cid', array('10', 20));
<?php // [SQL] SELECT count(*) cnt FROM `test1` WHERE `s` = ? [BVALUES] 0 $select = new Asf_Db_QueryBuilder_Select(); $select->count('*', 'cnt')->from('test1')->where('s', 0);
<?php // [SQL] SELECT * FROM `test` LIMIT 0, 10 $select = new Asf_Db_QueryBuilder_Select(); $select->cols()->from('test')->limit(0, 10);
<?php // [SQL] SELECT * FROM `test` a LEFT JOIN `image` b INNER JOIN `art` b ON a.id = b.id GROUP BY a.id ORDER BY a.id ASC $select = new Asf_Db_QueryBuilder_Select(); $select ->cols() ->from('test', 'a') ->leftJoin('image', 'b') ->InnerJoin('art', 'b') ->on('a.id', 'b.id') ->groupBy('a.id') ->orderBy('a.id', 'ASC');
<?php // [SQL] SELECT max(`username`) , min(`username`) , sum(`username`) , count(`username`) , distinct(`username`) FROM `test` a $select = new Asf_Db_QueryBuilder_Select(); $select ->max('username') ->cm(',') ->min('username') ->cm(',') ->sum('username') ->cm(',') ->count('username') ->cm(',') ->distinct('username') ->from('test', 'a');
<?php // [SQL] SELECT * FROM `test1` WHERE `id` > ? AND `status` = ? UNION ALL SELECT * FROM `test1` WHERE `id` < ? [BVALUES] 100 , 2 , 50 $select = new Asf_Db_QueryBuilder_Select(); $select->cols()->from('test1')->where('id', '100', '>')->where('status', 2) ->unionAll() select()->cols()->from('test1')->where('id', '50', '<');
<?php // [SQL] SELECT `a`, `b`, `c`, `d` FROM `test` WHERE `k` = ? [BVALUES] 1 $select = new Asf_Db_QueryBuilder_Select(); $select->cm('a, b, c, d')->from('test')->where('k', 1); var_dump($select->show());
<?php // SELECT * FROM `news` WHERE `status` = ? ORDER BY `id` DESC limit 0, 10 $limit = 'limit 0, 10'; Asf_Db::init(...) Asf_Db::QBS() ->cols()->from('news') ->where('status', 0) ->orderBy('id', 'DESC') ->cm($limit) ->exec();
<?php // UPDATE `news` SET `status` = ? WHERE `id` = ? Asf_Db::init(...) Asf_Db::QBU() ->table('news') ->set('status', 1) ->where('id', $id) ->exec();
<?php // SELECT `a`, `b`, `c` FROM `cart` WHERE `status` = ? ORDER BY `id` DESC LIMIT 50 Asf_Db::init(...) Asf_Db::QBS() ->cols(array('a', 'b', 'c')) ->from('cart') ->where('status', 0) ->orderBy('id', 'DESC') ->limit(50) ->exec();
<?php // SELECT count(`id`) cnt FROM `cart` WHERE `status` = ? Asf_Db::init(...) $data = Asf_Db::QBS() ->count('id', 'cnt') ->from('cart') ->where('status', 0) ->exec(1); echo $data['cnt'];
<?php // [SQL] SELECT `a`, `b`, `c`, `d` FROM `test` WHERE `k` like '%?%' [BVALUES] 1 $select = new Asf_Db_QueryBuilder_Select(); $select->cols(array('a', 'b', 'c', 'd'))->from('test')->like('k', 1);
<?php // [SQL] SELECT * FROM `test` WHERE `d` = ? AND `g` = ? ORDER BY `id` DESC [BVALUES] 1 , hhh $select = Asf_Db::qbs(); $select->cols()->from('test')->wheres(array('d' => 1, 'g' => 'hhh'))->orderBy('id');
If cols(string) Fields will not be escaped. If cols(array) Fields will be escaped(`字段名`)
<?php // string(55) "[SQL] SELECT distinct(`model`) ,id as ids FROM `test1`" $select = Asf_Db::qbs(); $select->distinct('model')->cols(',id as ids')->from('test1');