Created
December 16, 2013 04:20
-
-
Save settermjd/7982252 to your computer and use it in GitHub Desktop.
An example of using an SQL Expression in Zend\Db\Sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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