I am working on an application using Zend framework 2. I'm using TableGateway to select, insert, update and delete query.
1. My question is how to print exact sql query before executing INSERT, UPDATE and DELETE statement? For SELECT statement here is my code which is working for me.
$selectedTable = new TableGateway($this->tblName, $this->dbAdapter);
$sql = $selectedTable->getSql();
$select = $sql->select();
if ($trace) {
echo "<br>" . $sql->getSqlstringForSqlObject($select) . "<br>";
exit;
}
else {
$resultSet = $selectedTable->selectWith($select);
unset($selectedTable);
return $resultSet;
}
2. For last inserted id I'm using this code and working fine.
$selectedTable = new TableGateway($this->tblName, $this->dbAdapter);
$selectedTable->insert($dataArray);
$insertId = $selectedTable->adapter->getDriver()->getConnection()->getLastGeneratedValue();
unset($selectedTable);
return $insertId;
But for UPDATE how to get last updated id? and for DELETE how to get affected row? Because for UPDATE and DELETE this code is not working.
Can anyone suggest how to do these job?