PHP PDO vs normal mysqli speed performance benchmark
Solution 1
I doubt using PDO or MySQLi will be bottleneck, though, if you ask for bechmarks, here they are (nothing serious, just couple of tests).
In general, using one or another is a matter of taste, and bottlenecks usually are somewhere else (e.g., queries, indexes, PHP code etc).
One thing you might consider is using some DB wrapper, i.e., class that uses either PDO or MySQLi, whichever you prefer. In your code, use this wrapper instead of using PDO or MySQLi directly. If you do this, you'll be able to switch between PDO, MySQLi or any other library by changing single class instead of changing all the code.
Solution 2
I did a mini benchmark on this a while back. Conclusion. PDO and MySQLi are very similar but the features in PDO are worth using.
http://cznp.com/blog/2/apples-and-oranges-mysqli-and-pdo
Bhavesh G
Over 10+ years of extensive experience in full-stack web development. Technologies include PHP (5.6, 7, CodeIgniter, Zend Framework, Custom Frameworks), HTML(5), CSS(3), MySQL, SQL, Javascript, web services, SOAP and REST API development jquery, Bootstrap, GIT, LAMP/Apache/NGINX Environment, Linux, MVC methodology, Object-Oriented design, UX and UI responsive design, making functional specs, application design, and architecture, Over 1-4 years of experience in: Amazon AWS / Azure / Heroku cloud, Node.JS, C#, Python, Redis, Memcached, WebRTC, integration, highly adaptive to latest tools and technologies Great at debugging/troubleshooting code, having best practices in coding and software engineering, Agile Development environment
Updated on June 14, 2022Comments
-
Bhavesh G almost 2 years
i m working on a project about social networking website where speed optimization is very critical.
is PDO is FASTER ?
i am thinking to switch to PDO is it recommended for use PDO for such a site ?
-
Bhavesh G almost 13 yearswhich DB wrapper will be good for a high traffic website ? will u recommend any good DB wrapper class ?
-
binaryLV almost 13 yearsI cannot recommend any, as I've never used any openly available wrapper. For my projects it's enough with simple class that has few classes -
select($sql, array $params)
,selectRow($sql, array $params)
,selectCol($sql, array $params, $valueColumn, $keyColumn)
,selectValue($sql, array $params)
for selecting data andexec($sql, $params)
for inserting, updating and deleting data. All selects return array of data (selectValue()
returns string or null),exec()
returns boolean.$sql
is a query for prepared statement,$params
are values to be bound. -
Bhavesh G almost 13 yearscan u give me the wrapper u used in ur project .. thank you
-
binaryLV almost 13 yearsNo ;) But it should not be difficult to write it yourself.
-
Bhavesh G almost 13 yearsyes you are right but it will be good if i've some references and also i can improve the existing code for better perfomance ... so if u can send then plz kindly send me .. all help will be considered.. thanks
-
binaryLV almost 13 yearsI cannot give you my wrapper, as it (a) belongs to my employer and (b) is incomplete.
-
Bhavesh G almost 13 yearsok i've completed the wrapper. thank you for your reply
-
Chris Baker about 10 yearsAnd c) you should make your own so you know exactly how it works and what it does. Libraries are great, but IMO you should learn the underlying technology first, decide what is and isn't a pain in the butt, then maybe get a library to make those things less annoying. If you skip straight to the shortcut, you have no idea what you're cutting, and it turns into a longcut (if that's a term). Rolling your own wrapper teaches you about the underlying concept, and helps you decide if third party code is truly worth adding.
-
Abubakkar almost 8 yearslink not working !
-
Aadhil over 7 yearsis there any need for switching between pdo and mysqli?
-
Rudiger about 6 yearsDB connection failure, ironic.