Reputation: 261
i am working on ZF2. I would like to print the queries. How can i do in model files?
I am doing the form validation with db records - for already exist condition.
But, it would not work. So, i like to trouble-shoot the queries.
Upvotes: 1
Views: 269
Reputation: 1274
If your using TableGateway for executing queries then try the below piece of code.
After constructing the whole $select object -
$select = new Select(database_table_name);
$select->join(...);
$select->where(...);
...
....
$select->order(...);
/*Required lines of code to print the whole query*/
$sql = new \Zend\Db\Sql\Sql($this->tableGateway->adapter);
echo $sql->getSqlStringForSqlObject($select);
exit(); //(optional)
Upvotes: 0
Reputation: 3527
You would simply do:
echo $this->getSql();
Although this isn't a recommended way, but it works in a pinch.
Upvotes: 1