MySQL PHP =@ symbol

This is a discussion on MySQL PHP =@ symbol within the PHP Language forums, part of the PHP Programming Forums category; I've seen this in php.net $r=@mysql_query($query,$MySQL); and I do not understand what would be the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-17-2005
Angelos
 
Posts: n/a
Default MySQL PHP =@ symbol

I've seen this in php.net $r=@mysql_query($query,$MySQL);
and I do not understand what would be the difference of this :
$r=mysql_query($query,$MySQL);

I mean what is the purpose of " =@ " ?
Does anyone know ? I am Just curious
Thanks



Reply With Quote
  #2 (permalink)  
Old 05-17-2005
Chris Hope
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

Angelos wrote:

> I've seen this in php.net $r=@mysql_query($query,$MySQL);
> and I do not understand what would be the difference of this :
> $r=mysql_query($query,$MySQL);
>
> I mean what is the purpose of " =@ " ?
> Does anyone know ? I am Just curious


It prevents errors from being displayed when the function is called.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Reply With Quote
  #3 (permalink)  
Old 05-17-2005
Angelos
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

>> I've seen this in php.net $r=@mysql_query($query,$MySQL);
>> and I do not understand what would be the difference of this :
>> $r=mysql_query($query,$MySQL);
>>
>> I mean what is the purpose of " =@ " ?
>> Does anyone know ? I am Just curious

>
> It prevents errors from being displayed when the function is called.


That sounds usefull... but I thought that if error reporting is OFF then
errors are not displayed but then again you propably mean that it doesn't
display MySQL errors...
;-)


Reply With Quote
  #4 (permalink)  
Old 05-17-2005
Chris Hope
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

Angelos wrote:

>>> I've seen this in php.net $r=@mysql_query($query,$MySQL);
>>> and I do not understand what would be the difference of this :
>>> $r=mysql_query($query,$MySQL);
>>>
>>> I mean what is the purpose of " =@ " ?
>>> Does anyone know ? I am Just curious

>>
>> It prevents errors from being displayed when the function is called.

>
> That sounds usefull... but I thought that if error reporting is OFF
> then errors are not displayed but then again you propably mean that it
> doesn't display MySQL errors...


If error reporting is set to *show* errors, then the @ symbol before a
function call will prevent the error from displaying. Obviously it
won't show if error reporting is set to not show them ;)

MySQL errors aren't displayed anyway, unless you make a syntax error
when calling the function. To find out if MySQL returned an error you
need to use the mysql_error() or mysql_errno() functions.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Reply With Quote
  #5 (permalink)  
Old 05-17-2005
Angelos
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

> MySQL errors aren't displayed anyway, unless you make a syntax error
> when calling the function. To find out if MySQL returned an error you
> need to use the mysql_error() or mysql_errno() functions.


oh ok, didn't know that...
I always use mysql_error() anyway...


Reply With Quote
  #6 (permalink)  
Old 05-17-2005
Good Man
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

"Angelos" <angelos@redcatmedia.net> wrote in news:d6ck7q$fo7$1
@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:

>> MySQL errors aren't displayed anyway, unless you make a syntax error
>> when calling the function. To find out if MySQL returned an error you
>> need to use the mysql_error() or mysql_errno() functions.

>
> oh ok, didn't know that...
> I always use mysql_error() anyway...


the '@' is most valuable when you're requesting variables that have been
POSTed or REQUESTed:

@$Name = $_POST['Name'];

So, in case someone DIDN'T fill out the field 'Name', the script won't go
all ugly. It lets you handle errors gracefully. Without the @ in the
above line, the output would be "Notice: Undefined Variable 'Name'" or
something. Instead I can just add:

if ($vName=="") {
echo "Sorry, please fill out your name.";
exit;
}

.... to handle the error gracefully...
Reply With Quote
  #7 (permalink)  
Old 05-17-2005
Chris Hope
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

Good Man wrote:

> "Angelos" <angelos@redcatmedia.net> wrote in news:d6ck7q$fo7$1
> @nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
>
>>> MySQL errors aren't displayed anyway, unless you make a syntax error
>>> when calling the function. To find out if MySQL returned an error
>>> you need to use the mysql_error() or mysql_errno() functions.

>>
>> oh ok, didn't know that...
>> I always use mysql_error() anyway...

>
> the '@' is most valuable when you're requesting variables that have
> been POSTed or REQUESTed:
>
> @$Name = $_POST['Name'];
>
> So, in case someone DIDN'T fill out the field 'Name', the script won't
> go
> all ugly. It lets you handle errors gracefully. Without the @ in the
> above line, the output would be "Notice: Undefined Variable 'Name'"
> or
> something. Instead I can just add:
>
> if ($vName=="") {
> echo "Sorry, please fill out your name.";
> exit;
> }
>
> ... to handle the error gracefully...


You could do it like this instead of using the @, although your way is
less verbose.

$name = isset($_POST['name']) ? $_POST['name'] : '';

An advantage of doing it this way is it this way lets you specify a
default value.

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Reply With Quote
  #8 (permalink)  
Old 05-17-2005
Mike Willbanks
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

Chris,
> You could do it like this instead of using the @, although your way is
> less verbose.
>
> $name = isset($_POST['name']) ? $_POST['name'] : '';
>
> An advantage of doing it this way is it this way lets you specify a
> default value.


sometimes an even better way is with empty, for say if a field is
required data :)

if (empty($_POST['name'])) {
echo('Name must be filled out.');
}
Reply With Quote
  #9 (permalink)  
Old 05-17-2005
Philip Olson
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

if ($vName=="") { also produces E_NOTICE errors, so, don't do this.
Use isset() or empty(). Also for what it's worth, the @ error operator
is documented in the PHP Manual here:

http://php.net/manual/en/language.op...rorcontrol.php

Reply With Quote
  #10 (permalink)  
Old 05-17-2005
Chris Hope
 
Posts: n/a
Default Re: MySQL PHP =@ symbol

Mike Willbanks wrote:

> Chris,
>> You could do it like this instead of using the @, although your way
>> is less verbose.
>>
>> $name = isset($_POST['name']) ? $_POST['name'] : '';
>>
>> An advantage of doing it this way is it this way lets you specify a
>> default value.

>
> sometimes an even better way is with empty, for say if a field is
> required data :)
>
> if (empty($_POST['name'])) {
> echo('Name must be filled out.');
> }


That's cool. Isn't it fun how you can program in a language for 7 years
and still not know a little thing like that :)

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0