On Tue, Aug 2, 2011 at 2:47 PM, Julien Palard <jul...@meltynetwork.fr> wrote: > Hi Ferenc > > On Tue, Aug 2, 2011 at 2:35 PM, Ferenc Kovacs <tyr...@gmail.com> wrote: >> if you [...] force pdo to use real prepared statements, >> then you can reuse the compiled statements via using persistent >> connections. >> [...] >> >> does this answer your question? > > Yes you're exactly answering my question, so there already has a cache > in the driver that reuse the prepared queries on the same connection, > great ! > > So as I already use persistent connection, if I force PDO to use real > prepared queries, does I have something more to do to use this cache ? > And is there any documentation about it ? > > Bests, > -- > Julien Palard >
you shouldn't need anything else AFAIK. the docs somehow scarce on this topic. :( you can read more about that pdo offers emulated prepared statements: http://docs.php.net/manual/en/pdo.prepared-statements.php and how the persistent connection works: http://php.net/manual/en/features.persistent-connections.php http://php.net/manual/en/pdo.connections.php about the prepared statements in mysql: http://dev.mysql.com/doc/refman/5.1/en/c-api-prepared-statements.html http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html to summarize it: prepared statements are good from the security point of view: the query and the arguments will send separately to the server, so sql injection is impossible. you can use prepared statements for performance gain, but it's only worth it, if you use a prepared statement more than once. as the prepared statements tied to the connection, using non persistent connections would mean that you have to prepare your statement for every request, so you can only achieve performance improvement, if you use that statement more than once in that script execution. if you can use persistent connection, the performance gain will accumulate between your requests. I think this would worth a blogpost, also cc'd the phpdoc mailing list, maybe somebody would be interested to add this to the documentation. Tyrael -- Ferenc Kovács @Tyr43l - http://tyrael.hu