mymotherland mymotherland - 8 months ago 64
MySQL Question

How to print exact sql query in zend framework ?

I have the following piece of code which i taken from model,

$select = $this->_db->select()
echo $select; exit; // which gives exact mysql query.

When i use update query in zend like ,

$up_value = array('billing'=> '0');
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);

Here i want to know the exact mysql query. Is there any possible way to print the mysql query in zend ? kindly advice


Select objects have a __toString() method in Zend Framework.

From the Zend Framework manual:

$select = $db->select()

$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.


// your code
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);