How to print exact sql query in zend framework ?

前端 未结 14 2027
栀梦
栀梦 2020-12-07 09:33

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

    ...
                  $select = $this->_db->select()
                    ->from($th         


        
14条回答
  •  感情败类
    2020-12-07 10:28

    The query returned from the profiler or query object will have placeholders if you're using those.

    To see the exact query run by mysql you can use the general query log.

    This will list all the queries which have run since it was enabled. Don't forget to disable this once you've collected your sample. On an active server; this log can fill up very fast.

    From a mysql terminal or query tool like MySQL Workbench run:

    SET GLOBAL log_output = 'table';
    SET GLOBAL general_log = 1;
    

    then run your query. The results are stored in the "mysql.general_log" table.

    SELECT * FROM mysql.general_log
    

    To disable the query log:

    SET GLOBAL general_log = 0;
    

    To verify it's turned off:

    SHOW VARIABLES LIKE 'general%';
    

    This helped me locate a query where the placeholder wasn't being replaced by zend db. Couldn't see that with the profiler.

提交回复
热议问题