Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i find the sql query statement of insert() in Zend Framework?

How can i find the sql query statement in Zend Framework for insert(), like its done for db table select's. $select->__toString().

like image 534
Unni Krishnan Avatar asked Nov 26 '22 12:11

Unni Krishnan


1 Answers

Try this which work for me:

    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
    $db->getProfiler()->setEnabled(true);
    $profiler = $db->getProfiler();

    $lastID = ($this->insert($data));

    $query = $profiler->getLastQueryProfile();
    $params = $query->getQueryParams();
    $sqlQuery= $query->getQuery();

    foreach ($params as $par) {
        $sqlQuery = preg_replace('/\\?/', "'" . $par . "'", $sqlQuery, 1);
    }
    echo $sqlQuery;
like image 161
Satish Avatar answered Apr 29 '23 05:04

Satish