我使用过ZF1 DB适配器,现在正在学习ZF3,但我似乎找不到相当于:
$rows = $db->fetchAll('select * from `my_table`');
$row = $db->fetchRow('select * from `my_table` where `id` = 1');
$values = $db->fetchCol('select `my_col` from `my_table`');
$value = $db->fetchOne('select `my_col` from `my_table` where `id` = 1');我在ZF3中找到的使用prepare语句的示例。那么,在ZF3中,如何做到以上每一行1行呢?
发布于 2017-08-03 16:00:30
一个词:走了。现在,您必须处理ResultSet\ResultSetInterface接口。但它是一个迭代器。你当然不会有任何困难得到结果。
发布于 2017-08-04 08:32:11
是的,它不见了。
您可以按照与ZF1相同的方式构建select。我的代码中的示例:
// From Mapper that extends AbstractTableGateway
// and implements AdapterAwareInterface
$select = $this->getSql()->select()
->join('articles', 'article_events.article_uuid = articles.article_uuid')
->where(['articles.article_id' => $id]);
$result = $this->selectWith($select);
// $result; is fetchAll()
// $result->current(); is fetchRow() or fetchOne()
// $result->current()->col_name is fetchCol();https://stackoverflow.com/questions/45482596
复制相似问题