PDO :: query vs. PDOStatement :: execute (PHP and MySQL)

I have extended the PDO class to create a simple DB class and am currently using prepare + execute for all queries running in the database, even those that have no parameters (e.g. SELECT * FROM table).

Question: is there a performance advantage for using PDO :: query for simple queries that have no parameters, and not for preparation / execution?

+8
php mysql pdo prepared-statement
source share
2 answers

Yes, because when you call PDO::prepare , the server must create a query plan and meta-information for this request, then there is additional overhead for binding the specified parameters when using PDO::execute . Thus, to save this overhead and improve performance, you can use PDO::query for queries without parameters.

However, depending on the scale and size of your application and the configuration of your server / host (public / private), you may or may not see any performance increase whatsoever.

+8
source share

There is a noticeable difference between how to do things in PHP differently. You must evaluate the value that each method has for you and create test cases to see if you should do something anyway.

+1
source share

All Articles