开发者

Zend_Db query and row count without pulling back everything up front

I've created my select:

$select = $zdb->select()
              ->from(array("b" => "blogs"),
                     array("id", "active", "updated_by", "title", "synopsis", "create_date", "body"))
              ->join(array("u" => "users"),
                     'b.updated_by = u.id',
                     array("first_name", "last_name"))
              ->where("u.blogger = ?", 1)
              ->where("b.publish_date > ?", '2020-01-01')
              ->where("b.active = ?"开发者_StackOverflow, 1)
              ->group("b.id")
              ->order("b.publish_date DESC")
              ->limit(5);

and I want to pull the data back a row at a time:

$stmt = $db->query($select);

while ($asset = $stmt->fetch()) {
    // do stuff
}

How can I check to make sure that there are rows, without returning the entire resultset?


Using the select you already have, something like that should help you parse every entry

$rows = $zdb->fetchAll($select);

foreach($rows as $row){
    ...
}

To get the values you just have to do $row['fieldName'] where fieldName is the name of the field in your database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜