Home › Forums › Back End › PHP PDO API Calls › Re: PHP PDO API Calls
$start = microtime( true );
/* do PDO stuff
* (it will likely be necessary to perform
* the same task repeatedly, in a loop,
* to get a meaningful time period).
$stop = microtime( true );
$execution_time = $stop – $start;
As for the rest of your post, I am unsure what your actual question is, so this may or may not apply:
The single most time-consuming portion of any database API, by *far*, is the part where it actually queries the database. The process of sending a query, waiting for a response, and receiving the result can be called a “round-trip.”
If you want to speed up your database-related code, simply rewrite your code to make as few round-trips as possible.
… never use multiple queries where one would do (e.g., INSERT multiple records with the same statement)
… use JOINs and MySQL functions (aggregate functions, etc.) to combine queries involving multiple tables
… use TRANSACTIONs and multi-step queries (this is the main reason I prefer MySQLi over PDO: transactions and multi-queries are much easier)
… don’t query the DB when you don’t have to (this may seem obvious, but I see it all the time).