Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve insert query used in save() function

Tags:

cakephp

The following data I have to insert using save(). The data is from html table.

Array
(
[Test] => Array
    (
        [1] => Array
            (
                [patient_id] => 58
                [dt_test] => 2012-06-04
                [name] => dfg
                [result] => 34
            )

        [2] => Array
            (
                [patient_id] => 58
                [dt_test] => 2012-06-18
                [name] => dsfg
                [result] => 76
            )

    )

) The id is the primary key of 'test'

There is no validation error. But not any row is inserting into the table 'test'. How can I check the sql query used to insert the data. My db is postgres and version is 1.3

like image 599
alexkd Avatar asked Aug 20 '26 19:08

alexkd


1 Answers

To see queries you need to enable debug mode. In /cakephp/app/config/core.php you have to set debug level:

Configure::write('debug', 2);

then you can print all queries by putting this code in your view file:

<?php echo $this->element('sql_dump'); ?>

If you prefer to display them from controller, then put this line after save():

debug($this->Test->getDataSource()->getLog(false, false));
like image 198
Zbigniew Avatar answered Aug 23 '26 02:08

Zbigniew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!