Grow your CSS skills. Land your dream job.

PHP PDO API Calls

  • # December 3, 2012 at 7:30 pm

    * How would I determine how much time is being spent in each PDO API call? I am aware of differentiating the amount DB execution time from the amount of time in each API call. (Interested in another other option)

    * How would this solution impact the maintainability of my application? Specifically, if a new framework is added to the application how would this solution time PDO calls in the framework?

    * In what ways could this solution change the performance characteristics of my application?*

    __
    # December 3, 2012 at 10:25 pm

    < ?php
    $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).

    # December 4, 2012 at 12:36 am

    Thanks for the comment. Its given me some thoughts

    __
    # December 4, 2012 at 1:11 am

    As I said, I wasn’t very clear about what you were actually asking. Did this answer your question?

    If not, please explain further, and I’ll do my best to answer.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".