Skip to content

Instantly share code, notes, and snippets.

@settermjd
Created December 16, 2013 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save settermjd/7982252 to your computer and use it in GitHub Desktop.
Save settermjd/7982252 to your computer and use it in GitHub Desktop.
An example of using an SQL Expression in Zend\Db\Sql
/**
* First construct the Select object for the SQL query to run
*/
$select = new Select('tblusers');
$select->columns(array(
"recordCount" => new \Zend\Db\Sql\Expression("COUNT(*)")
));
/**
* Then execute the query, retrieving the first record, if available
* This uses the RowGateway class <http://framework.zend.com/manual/2.0/en/modules/zend.db.row-gateway.html>
*/
if (!$row = $this->tableGateway->selectWith($select)->current()) {
throw new RecordSearchException("Could not find row $feedId");
}
/**
* Show the value of recordCount
*/
print $row->recordCount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment