Fast php question .

Discussion in 'PHP' started by mab, Jul 4, 2008.

  1. #1
    Hello ..

    well my question is .. which is better to use ?

    
    <?php
    
    include('config.php');
    	$load = "SELECT * FROM members WHERE user_name='$uusername'";
    	$query = mysql_query($load,$conn) ;
    	$row = mysql_fetch_object($query);
    	$name = $row->name;
    	echo "Hello .. My name is $row->name"; // This ???
    	echo "Hello .. My name is $name"; // or this ??
    ?>
    
    PHP:
    well i'm talking about which is faster ? better ?

    Thanks :)
     
    mab, Jul 4, 2008 IP
  2. projectWORD

    projectWORD Active Member

    Messages:
    287
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    I would say if you define $row->name as a variable, you may aswell use that variable. If you didn't bother defining $row->name as a variable, maybe that way would be quicker.
    Personally, I would define it as a variable and then use the variable. It seems more sensible to do so as you can call it something specific for later use and its a lot easier to type to re-use.
    I would say there isn't really a speed issue here
     
    projectWORD, Jul 4, 2008 IP
    mab likes this.
  3. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could also set that as an obj as well and then just call the obj name

    but definitely $row->name;
     
    IGiveMoney, Jul 4, 2008 IP
    mab likes this.
  4. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Got it .. Thanks dude for your help :) .
     
    mab, Jul 4, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Danltn, Jul 4, 2008 IP
  6. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #6
    i have been using mysql_fetch_array but i've heard that is mysql_fetch_object is better and faster :(
     
    mab, Jul 4, 2008 IP
  7. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i usually just use mysql_fetch_array() and never have any problems with it.
     
    IGiveMoney, Jul 4, 2008 IP
  8. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #8
    The same with mysql_fetch_object :)
     
    mab, Jul 4, 2008 IP
  9. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #9
    No, mysql_fetch_array is faster, hence better.

    Functionality is the same but the OOP overhead is pointless.

    It's practically just calling mysql_fetch_array then setting the type to an (object).

    Dan
     
    Danltn, Jul 6, 2008 IP