我开始Zend Framework 2
,我想用我的用户角色做出路由选择,我必须写getRoleByID($id)
,
那我怎么写
" Select 'role' from user where ('id' = $id) "
使用 Zend\Db\Sql
我开始Zend Framework 2
,我想用我的用户角色做出路由选择,我必须写getRoleByID($id)
,
那我怎么写
" 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) { /* ... */ }