Reply to PDOStatement::prepare overhead

Your name:

Reply:


Posted by Gordon on 01/02/08 14:52

With the move over to PHP 5.x I' mnow writing a lot of code that makes
use of prepared statements as the PHP manual has nothing but good
things to say about them. They have less overhead for the database,
they eliminate the possibility of SQL injection attacks, they are made
of sunshine and fluffy kittens, etc.

Then I got to thinking, in my methods I am preparing a statement and
then running it one to n times, depending on the method and what its
doing. But of course when you go out of scope in a method you destroy
the PDOStatement that you prepared. Of course it gets recreated when
you next run the function, but then what happens whtn the prepare()
statement is run again?

I'm working with Postgres so I assume the PDO driver is using the
prepared statement support already built into Postgres as opposed to
the PDO emulation layer. So what I want to know is what happens when
you prepare the same statement more than once, with different
PDOStatement objects? Will the entire query preparation process run
again or does the prepared statement get cached server side? From the
point of view of program logic it makes very little difference whether
or not the statement is prepared over from scratch, but I would
imagine that there is a performance price to be paid that would
totally negate the performance advantage of prepared statements for
queries that are only run once.

The reason I am asking this is to determine whether or not it is worth
the effort to modify my database querying classes so they store all
prepared statements in static variables? Doing so would allow me to
initialize each prepared statement as needed and only do it once per
page view, but it would require a fair amount of rewriting, a day or 2
at least. I'm wondering if the performance benefit would be enough to
justify the work involved.

Any comments you guys have would be appreciated.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация