SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Use EXPLAIN

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use EXPLAIN

    Hi,

    Is there a way of using and displaying the outcome of a query using EXPLAIN within PHP?

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What the heck do you mean? please explain

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All I know about EXPLAIN is to use it in the 'dos' interface.
    How can I use it within a PHP script to show what I would see in the 'dos' interface on a web page?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Let's not call it the "dos" interface, DOS was an operating system. It's the mysql client, or a command line interface

    You can do exactly what you do with SELECT queries, it'll work with EXPLAIN:

    PHP Code:
    mysql_connect('localhost''user''pass');
    mysql_select_db('db');

    $res mysql_query('EXPLAIN SELECT id FROM purchases');
    while (
    $row mysql_fetch_assoc($res))
        
    print_r($row); 
    Code:
    Array
    (
        [id] => 1
        [select_type] => SIMPLE
        [table] => purchases
        [type] => index
        [possible_keys] =>
        [key] => PRIMARY
        [key_len] => 4
        [ref] =>
        [rows] => 953
        [Extra] => Using index
    )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •