473,511 Members | 17,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PDOStatement::prepare overhead

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.
Jan 2 '08 #1
0 1276

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2421
by: John Cecere | last post by:
I've run into this bug: http://bugs.php.net/bug.php?id=29902 I'm beside myself trying to get around this. My application is dying after processing 20 transactions because there is no way to...
2
2501
by: James | last post by:
Hey everyone... I'm having an issue with a seemingly simple piece of PHP/MySQL I have a stored procedure in MySQL5 as such: SQL: -------------- DELIMITER $$; DROP PROCEDURE IF EXISTS...
3
3427
by: DavidPL | last post by:
Hello, I have some problem with bind method in PDO on Oracle with clob | long column type. I have table named TEST_TABLE where I have two columns: ID (int 10, 0) and TEXT (varchar 4000 or long...
5
16486
by: loudwinston | last post by:
Hello, I'm encountering a strange error with PDO. The server is FreeBSD 4.4, PHP 5.1.2, mySQL 4.0.20 with 4.1.18 client libs. I have the following code (usernames and passwords changed to...
6
8098
by: Tonio | last post by:
Hello, I got and an exception handler, and I want, for each PDOException throwned, to get the whole query which didn't works. Is there a way to do this ? Thanks, Tonio
3
2444
by: Gilles Ganault | last post by:
Hi APC doesn't like it when I store the output of a SELECT: === include("apc.php"); $dbh = new PDO("sqlite:./test.sqlite"); $sql = "CREATE TABLE IF NOT EXISTS mytable (name TEXT)";
6
9648
by: Gordon | last post by:
I want to search a folder structure represented in a database. I'm using the ID and Parent columns model, and would like to be able to search a folder's subfolders as well as teh folder itself. ...
2
1290
Dormilich
by: Dormilich | last post by:
Hi, currently I'm stuck on finding the error of one of my functions. I try to read data out of MySQL using PDO. the SQL string is loaded as Prepared Statement (PDO->prepare()) and shall be...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.