Impeared performance?

Bad puns aside, it is a legitimate concern if you are wondering at what cost the power of PEAR::DB comes. When you use direct database function calls, such as mysqli_query(), there is no need to jump through hoops to figure out what database type is being referenced or the like, because the call is unambiguous. In PEAR::DB, a lot of extra work has to be done behind the scenes to make it work smoothly across the different DBMSs, and this has quite a heavy speed toll.

On average, you are likely to find PEAR::DB code will run at about 3/8 the speed of the equivalent DBMS-specific code (that is, just less than half the speed), although this will of course vary depending on the types of query you do. It is of course impossible for PEAR::DB to ever run as fast as native DBMS calls because PEAR::DB is written using PHP, and PHP scripts are much slower than compiled C programs.

However, you need to weigh the performance hit against the extra flexibility offered by PEAR::DB. PEAR::DB code can be transferred from MySQL to PostgreSQL to Microsoft SQL Server to Oracle, all simply by changing the initial DSN used to connect to the server. Furthermore, functionality such as prepared statements bring the database code closer to that of Microsoft's ADO technology, and should therefore help entice ASP and ASP.NET programmers over to PHP.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: SQLite >>

Previous chapter: Advanced PEAR::DB

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.