SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which one is faster?

    Hi,

    I have a simple Q: Which one is faster?

    PHP Code:
    <?php
    error_reporting
    (0);
    ini_set('display_errors''0');

    require_once 
    'adodb_lite/adodb.inc.php';

    if (!isset(
    $_GET['q']) || (!$q=$_GET['q'])) {
        exit();
    }

    $db ADONewConnection('mysql');

    $ADODB_FETCH_MODE ADODB_FETCH_NUM;

    if (!
    $rt $db->PConnect('localhost''test''test''autocomplete')) {
        exit();
    }

    if (!
    $rs $db->Execute('SELECT v FROM ac WHERE v LIKE "%'.addslashes($q).'%"')) {
        exit();
    }

    while (!
    $rs->EOF) {
        echo 
    $rs->fields[0],"\n";
        
    $rs->MoveNext();
    }
    ?>
    vs

    PHP Code:
    <?php
    error_reporting
    (0);
    ini_set('display_errors''0');

    require_once 
    'adodb_lite/adodb.inc.php';

    if (isset(
    $_GET['q']) && ($q=$_GET['q'])) {
        
    $db ADONewConnection(DB_TYPE);
        
        
    $ADODB_FETCH_MODE ADODB_FETCH_NUM;
        
        if (
    $rt $db->PConnect('localhost''test''test''autocomplete')) {
            if (
    $rs $db->Execute('SELECT v FROM ac WHERE v LIKE "%'.addslashes($q).'%"')) {
                while (!
    $rs->EOF) {
                    echo 
    $rs->fields[0],"\n";
                    
    $rs->MoveNext();
                }
            }
        }
    }
    ?>
    Thanks,

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first is theoretically just slightly faster, but so little you wouldn't notice. It's easy to test. But the first is also bad practice in general. It's best to have complete code without various exits throughout.


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
  •