0
我開始與Zend Framework 2
,我想作出路由選擇與我的用戶的角色,我必須寫getRoleByID($id)
,的Zend/DB/SQL /查詢語法
然後 如何can'I寫
" Select 'role' from user where ('id' = $id) "
與Zend \ Db的\ SQL
我開始與Zend Framework 2
,我想作出路由選擇與我的用戶的角色,我必須寫getRoleByID($id)
,的Zend/DB/SQL /查詢語法
然後 如何can'I寫
" Select 'role' from user where ('id' = $id) "
與Zend \ Db的\ SQL
示例使用選擇:
$select = new \Zend\Db\Sql\Select('user');
$select->columns(array('role'));
$where = new Where();
$where->equalTo('id', $id);
$select->where($where);
/**
* Simple example of executing a query...
*/
$stmt = $this->getSql()->prepareStatementForSqlObject($select);
$results = $stmt->execute();
/* @var $results \Zend\Db\Adapter\Driver\Pdo\Result */
if(! $results->count()) {
// do something, none found...
}
$row = $results->current();
return $row['role'];
// if you had multiple results to iterate over:
//$resultSet = new \Zend\Db\ResultSet\ResultSet();
//$resultSet->initialize($results);
//$array = $resultSet->toArray();
//foreach($resultSet as $row) { /* ... */ }
謝謝你的reponce,這是非常有幫助的。只有一個問題,我必須執行查詢 // $ stmt = $ this-> getSql() - > prepareStatementForSqlObject($ select); $ results = $ stmt-> execute(); //可以與結果進行比較? – Loouu