Executing queries using TableGateway
After we have seen how to execute simply queries, it is now time to tell you about the TableGateway
, and it's incredible functionality. This recipe is all about querying the database through this and showing off its capabilities.
Getting ready
To make full of the following recipe, a Zend Framework 2 skeleton application should be used, with a MySQL server available to connect to. Don't forget that connecting to a MySQL server requires the mysql
and mysqli
extension enabled in PHP.
How to do it…
What we are going to do first is insert a record in our sample table. After that we will check that it was inserted successfully. Next, we will update the record with some new data, and if that worked we will delete it again from the table.
Inserting a new record
Before we go about updating a record, it might be handy if we actually have a record that we can use to update first. Zend Framework 2 has some new nifty database tools that make our lives a little easier when...