Search code examples
zend-framework2

How to view db queries generated by TableGateway in Zend Framework 2


I am brand new to ZF2 and am trying to use a tableGateway to manage and update entries in a database. I am able to select and update items without a problem, but when inserting I get an error. Since the tableGateway class creates the query on the fly, how can I see the query itself?

$this->tableGateway->insert($data);

An error occurred during execution; please try again later. Additional information: Zend\Db\Adapter\Exception\InvalidQueryException

File:

/[redacted]/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php:220

Message:

Statement could not be executed

Solution

  • Very elegant way how to see db queries is to use zend-developer-tools.

    Easiest way how to use it is to install module by adding it to composer.json file

    ..... "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" } ], "require": { "php": ">=5.3.3", "zendframework/zend-developer-tools": "dev-master" }

    see documentation