嗨,我无法使用findby sql获得yii中的最后10个元素

时间:2014-03-03 07:57:02

标签: yii

 public function getGet($nid)
       {
          $sensor = $this->findBySql("select * from tbl_sensor where stype=4 and nid=$nid order by timestamp desc limit 10;");

        if ($sensor == NULL)
        return "NULL";
        return $sensor->sdata;
       }

1 个答案:

答案 0 :(得分:0)

试试这段代码。

echo "select * from tbl_sensor where stype=4 and nid=$nid order by timestamp desc limit 10";
$res= Yii::app()->db->createCommand("select * from tbl_sensor where stype=4 and nid=$nid order by timestamp desc limit 10")->queryAll();

//print_r($res); // will return array of result.
// to check query, print the query executed.

return $res;