Recently I was going through a blog and noticed some points about using PDO in mysql and it changed my view about the PDO. The points are :
Native prepared statements cannot take advantage of the query cache, resulting in lower performance.
Native prepared statements cannot execute certains types of queries, like "SHOW TABLES"
Native prepared statements don't correctly communicate column lengths for certain other "SHOW" queries, resulting in garbled results.
Calling stored procedures multiple times using native prepared statements causes the connection to drop.
Can anyone comment on this please?
I wanted query cache in my web app. I am preparing to move my web app to make use of PDO after considering performance issues with my website. Can anyone please suggest me?
Thanks in advance.
Well
You may use the following command to enable query caching:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
This command is available from PHP 5.1.3 on only.
Prepared statements DO use query cache, but it does have conditions:
From the 5.1 Doc:
Before MySQL 5.1.17, prepared statements do not use the query cache. Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which differ depending on the preparation method:
- Statements that are issued using the binary protocol using mysql_stmt_prepare() and mysql_stmt_execute().
- Statements that are issued using the text (nonbinary) protocol using PREPARE and EXECUTE. See Section 12.6, “SQL Syntax for Prepared Statements”.
Which the 5.5 Doc restates as:
Prepared statements that are issued using the binary protocol using mysql_stmt_prepare() and mysql_stmt_execute(), are subject to limitations on caching. Comparison with statements in the query cache is based on the text of the statement after expansion of ? parameter markers. The statement is compared only with other cached statements that were executed using the binary protocol. That is, for query cache purposes, prepared statements issued using the binary protocol are distinct from prepared statements issued using the text protocol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With