There has been a feature request for a long time to provide this alternative, but no one has developed it. http://framework.zend.com/issues/browse/ZF-1398

Keep in mind that the round-trip you fear incurs too much overhead is actually not always a problem. This article shows that at least in some cases, a prepared MySQL query actually runs 14% _faster_ than a non-prepared query:
http://www.mysqlperformanceblog.com/2006/08/02/mysql-prepared-statements/

Don't suppose you have a problem that needs to be solved. First, measure the performance and identify whether you have a problem -- and if so, how bad is the problem. Besides, this gives you the chance to measure again afterwards to be certain that you've mitigated the problem if there is one.

If you do need to run a query that doesn't work as a prepared statement (there are still a few even in MySQL 5.1, such as CREATE TRIGGER), you have this workaround:

$db = Zend_Db::factory( ... );
$sql = "CREATE TRIGGER ...";
$db->getConnection()->query($sql);

You could also use exec() if your Db adapter uses PDO, but query() will work in both PDO and MySQLi.

Regards,
Bill Karwin

On Jun 7, 2010, at 8:07 AM, Ryan Chan wrote:

I have traced the source code of ZFW, and found the database adapter
Zend_Db_Adapter_Mysqli  always do a prepare when execute any SQL.

However, I found it is not needed, since most of my query only run
once in their life cycle - no reuse is needed. It is possible to
disable auto prepare so it can save a MySQL roundtrip for the prepare
statement?

Reply via email to