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 16 28605
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
>> 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...
;-)
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
> 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...
"Angelos" <an*****@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...
Good Man wrote: "Angelos" <an*****@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
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.');
}
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
That's a common misconception, equating error messages with errors.
E_NOTICE and E_WARNING messages do not necessarily indicate errors.
Their purpose is to get a programmer to take a second look at some code
that could potentially be erroreous.
PHP emits a E_NOTICE or E_WARNING message whenever it fails to do
something (e.g. a hash table miss). Failures are not the same as
errors, one has to remember. When they're expected and are handled,
then there's nothing errorous in the code.
I don't understand why people insist that the use of isset() is good
practice. In order to see if an element is available in a hash table,
PHP has to look it. So you end up doing two hash lookups to get one
element.
Chung Leong wrote: That's a common misconception, equating error messages with errors. E_NOTICE and E_WARNING messages do not necessarily indicate errors. Their purpose is to get a programmer to take a second look at some code that could potentially be erroreous.
PHP emits a E_NOTICE or E_WARNING message whenever it fails to do something (e.g. a hash table miss). Failures are not the same as errors, one has to remember. When they're expected and are handled, then there's nothing errorous in the code.
I don't understand why people insist that the use of isset() is good practice. In order to see if an element is available in a hash table, PHP has to look it. So you end up doing two hash lookups to get one element.
I develop with the error reporting level to show notices so that I can
ensure I don't miss using a variable that hasn't yet been assigned (and
which certainly helps speed up debugging stupid coding issues).
If isset() is inefficient for the reason you have stated, then what
would you recommend as a more efficient method, given that you can
never assume a value has actually been passed to a page in a get or
post?
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
On 2005-05-17, Chris Hope <bl*******@electrictoolbox.com> wrote: 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 :)
Don't know which one is fastest:
- isset
- empty
- array_key_exists
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Tim Van Wassenhove wrote: On 2005-05-17, Chris Hope <bl*******@electrictoolbox.com> wrote: 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 :)
Don't know which one is fastest:
- isset - empty - array_key_exists
They're all essentially doing the same thing so they probably take about
the same amount of time.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Well, getting back to the OP's question, that's why we have the @
operator. If a message is bogus, just ignore it.
The method posted by Good Man above is what I use. You suppress the
error message from the hash access, then check the variable for
content:
$name = @$_POST['name'];
if(!$name) { ... }
More likely I would do:
$name = trim(@$_POST['name']);
if(!$name) { ... }
To distinguish between empty string and undefined variable:
$something = @$_GET['something'];
if(is_null($something)) { ... }
I mean that's how you'd access a hash table in C/C++: perform the look
up and deal with potential null results.
E_NOTICE is an error. E_ERROR is an error. E_PARSE is an error. These
are all errors of different levels, there is no misconception here.
Fact is you are promoting bad practice which is your right. Ask the
php.internals list and 100% of the people polled will tell you to use
isset() instead of @ here.
If you have an argument to make, make it. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by pancho |
last post: by
|
reply
views
Thread by renniw one |
last post: by
|
reply
views
Thread by Dennis Francis B. Tutanes |
last post: by
|
reply
views
Thread by al |
last post: by
|
4 posts
views
Thread by Ewok |
last post: by
|
reply
views
Thread by Greg O. |
last post: by
|
1 post
views
Thread by grabro |
last post: by
|
1 post
views
Thread by edfialk |
last post: by
|
5 posts
views
Thread by Jagadish Kumar, Maripi |
last post: by
| | | | | | | | | | | |