lezu
2010-12-02 13:26:22 +08:00
Querying Data
$res = $col->find(); SELECT * FROM `$tbl`
$doc = $col->findone(array('_id' => $id)); SELECT * FROM `$tbl` WHERE `id` = {$id}
$res = $col->find()->limit(1); SELECT * FROM `$tbl` LIMIT 1
$res = $col->find()->skip(1)->limit(1); SELECT * FROM `$tbl` OFFSET 1 LIMIT 1;
$res = $col->find()->sort(array('login' => -1)); SELECT * FROM `$tbl` ORDERBY `login` DESC //-1=DESC,1=ASC
$res = $col->find(array('age' => array('$lt' => 30))); SELECT * FROM `$tbl` WHERE `age` < 30 //$lt:<,$gt:>,$gte:>=, $lte:<=, $ne:!=
$doc = $col->find(array(’a'=>’hello’,'b’=>1)); SELECT * FROM `$tbl` WHERE `a` = ‘hello’ AND `b`=1
$doc = $col->find(array(’a'=>’hello’,'b’=>array(’$gt’=>1))); SELECT * FROM `$tbl` WHERE `a` = ‘hello’ AND `b`>=1
$res = $col->find(array('age' => array('$gte' => 20, '$lte' => 50))); SELECT * FROM `$tbl` WHERE `age` >= 20 AND `age` <= 50
$col->remove(array('age'=>24),array('justOne'=>true,'safe'=>true)); DELETE FROM `$tbl` WHERE `login` = 'psmith'