I have the following piece of code which i taken from model,
...
$select = $this->_db->select()
->from($th
Select objects have a __toString() method in Zend Framework.
From the Zend Framework manual:
$select = $db->select()
->from('products');
$sql = $select->__toString();
echo "$sql\n";
// The output is the string:
// SELECT * FROM "products"
An alternative solution would be to use the Zend_Db_Profiler. i.e.
$db->getProfiler()->setEnabled(true);
// your code
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);
Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
$db->getProfiler()->setEnabled(false);
http://framework.zend.com/manual/en/zend.db.select.html
Now on Zend2:
$select->getSqlString();
Displaying the generated SQL from ZendDbSql object
$statement = $this->sql->getSqlStringForSqlObject( HERE GOES Zend\Db\Sql\SelectSQL object );
echo "SQL statement: $statement";
Example:
$select = $this->sql->select();
...
$select->from(array( 'u' => 'users' ));
$select->join(...
$select->group('u.id');
...
$statement = $this->sql->getSqlStringForSqlObject($select);
echo $statement;
Check out the Zend_Db_Profiler. This allows you to log any SQL statement as it is prepared and executed. It works for UPDATE statements as well as SELECT queries.
even shorter:
echo $select->__toString()."\n";
and more shorter:
echo $select .""; die;
I have done this by this way
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from('mock_paper');
$select->columns(array(
'is_section'
));
$select->where(array('exam_id = ?' => $exam_id,'level_id = ?' => $level_id))->limit(1);
$sqlstring = $sql->buildSqlString($select);
echo $sqlstring;
die();