Zendfraemwork3 – Mysql Database and Model

In this example, I am going to show to how you can connect your data model to table in database and do the basic database operations like Select, Insert, Update, Delete

I am using Zendframework3 skeleton application, you can see this artille if you are not familiar with how to install it

Where do you put your database setting?
To your config.autoload.global.php file, you can add the following code to commect to Mysql database in your localhost

Now you can create the Product.php at Module\Application\src\Model and add the following code to it

You create the ProductTable.php at the same location and add the following code to do all database operations

What does TableGateway does in zendfraework?
TableGateway represents a table in a database. With the TableGateway interface you can do the most common table opretions like select,insert,update,delete

I can use the getServiceConfig() to load the factories. So you can add the following code to Module.php file loacted at Module\Application\src\

Finally you can add another configuration to module.config.php located at module\Application\config