2008年12月8日星期一

Re: [fw-core] Performance of Zend_Db_Select with named binding

Out of curiosity, is named binding select statements faster for repeated queries than using the regular quoted string syntax?

The API docs reference these 3 methods:

 // simplest but non-secure
 $select->where("id = $id");

  // secure (ID is quoted but matched anyway)
 $select->where('id = ?'$id); 

 // alternatively, with named binding
$select->where('id = :id');


In the last one, the actual value isn't quoted into the string, so you end up with a prepared statement without the values embedded, while the former two will result in a completely different query in each iteration.

Not knowing the ins and outs of query caching, I would assume that the 3rd option would be the fastest, since the query would only need to be prepared once, and then could be reused.

Can anyone confirm this?


Cheers,
David

没有评论: