mysql_result vs. (AT)mysql_result

Discussion in 'PHP' started by Giber, Aug 5, 2009.

  1. #1
    Is there any difference between:

    $id = @mysql_result($sql,0,"id");

    and

    $id = mysql_result($sql,0,"id");

    Note the @ sign before the mysql_result function.

    There is nothing in the Manual about, but there are snipetts around...
     
    Giber, Aug 5, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    The @ suppresses any error that the function would give. You would normally use this to prevent showing the actual error to the end user.

    Best bet is not to suppress but to use something like:

    if(!$id = mysql_result($sql,0,"id"))
    {
    die("There was an error with the result!");
    }

    or if you want to see the error:

    if(!$id = mysql_result($sql,0,"id"))
    {
    die(mysql_error());
    }
     
    jestep, Aug 5, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Surpressing errors with @ is bad and slows down your scripts. As the previous poster said, you have to look for it and then handle the error correctly within the if statement. Otherwise it's possible that the script continues execution and results in incorrect data being inserted in the DB, etc..

    If you want to surpress errors, simply use this:

    ini_set('display_errors', 0);
    PHP:
     
    premiumscripts, Aug 5, 2009 IP