而不仅仅是准备好的语句

而不仅仅是准备好的语句

本文介绍了教义 - 如何打印真正的sql,而不仅仅是准备好的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Doctrine,PHP ORM。我正在创建一个这样的查询:

  $ q = Doctrine_Query :: create() - > select('id' - >从( 'MyTable的'); 

然后在函数中,我添加各种各样的条款和事物,如此

  $ q-> where('normalisedname =?OR name =?',array($ string,$ originalString)); 

之后, execute()那个查询对象,我想打印出原始SQL以便检查它,并执行以下操作:

  $ q- > getSQLQuery(); 

但是,只打印出准备好的语句,而不是完整的查询。我想看看它是发送到MySQL,而是打印出一个准备好的声明,包括。有没有办法查看完整查询?

解决方案

原则不是向数据库发送真正的SQL查询服务器:它实际上是使用准备的语句,这意味着:




  • 发送语句,为准备(这是由...返回的 $ query-> getSql()

  • 然后,发送参数(由$ code $ $ query-> getParameters())

  • 并执行准备好的语句



这意味着PHP方面从来没有一个真正的SQL查询 - 所以Doctrine不能显示。


We're using Doctrine, a PHP ORM. I am creating a query like this:

$q = Doctrine_Query::create()->select('id')->from('MyTable');

and then in the function I'm adding in various where clauses and things as appropriate, like this

$q->where('normalisedname = ? OR name = ?', array($string, $originalString));

Later on, before execute()-ing that query object, I want to print out the raw SQL in order to examine it, and do this:

$q->getSQLQuery();

However that only prints out the prepared statement, not the full query. I want to see what it is sending to the MySQL, but instead it is printing out a prepared statement, including ?'s. Is there some way to see the 'full' query?

解决方案

Doctrine is not sending a "real SQL query" to the database server : it is actually using prepared statements, which means :

  • Sending the statement, for it to be prepared (this is what is returned by $query->getSql())
  • And, then, sending the parameters (returned by $query->getParameters())
  • and executing the prepared statements

This means there is never a "real" SQL query on the PHP side — so, Doctrine cannot display it.

这篇关于教义 - 如何打印真正的sql,而不仅仅是准备好的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:35