473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Jul 17 '05 #1
16 28684
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
Jul 17 '05 #2
>> 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...
;-)
Jul 17 '05 #3
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
Jul 17 '05 #4
> 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...
Jul 17 '05 #5
"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...
Jul 17 '05 #6
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
Jul 17 '05 #7
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.');
}
Jul 17 '05 #8
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

Jul 17 '05 #9
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
Jul 17 '05 #10
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.

Jul 17 '05 #11
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
Jul 17 '05 #12
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>
Jul 17 '05 #13
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
Jul 17 '05 #14
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.

Jul 17 '05 #15
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.

Jul 17 '05 #16
If you have an argument to make, make it.

Jul 17 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pancho | last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO on a Solaris 8 box - this module is needed to host some existing sites I will be migrating Note. I built PHP4 from source and...
0
by: renniw one | last post by:
Hi, Can anyone point me to a resource which details the process of compiling mysql server with openssl support on windows using VC++ preferable? If not, maybe someone has run across this problem...
0
by: Dennis Francis B. Tutanes | last post by:
$B$*@$OC$K$J$C$F$*$j$^$9!#(B $B%D%?%M%9(B@TSTI$B$G$9!#(B SEND-PR: -*- send-pr -*- SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as SEND-PR: will all comments (text...
0
by: al | last post by:
I am trying to compile mysql for windows with openssl support. I have: - Defined HAVE_OPENSSL and HAVE_VIO in client.c (in libmysql/d projects) and vio.c - linked the libmysql project to...
4
by: Ewok | last post by:
let me just say. it's not by choice but im dealing with a .net web app (top down approach with VB and a MySQL database) sigh..... Anyhow, I've just about got all the kinks worked out but I am...
0
by: Greg O. | last post by:
I'm getting link errors trying to compile the mysql++ library. Can anyone help? ========================== D:\PROGRA~1\mysql\MYSQL_~1.6>c:\progra~1\mingw\bin\mingw32-make | more cd lib &&...
1
by: grabro | last post by:
Having just upgraded to from Suse 10.0 to 10.1 mysql-administrator will not work. When I try to acccess it I get the following message. linux:/home/grabro # mysql-administrator...
1
by: edfialk | last post by:
Hi all, I'm desperately trying to get a simple mysql connection working in php 4.3.9 and I think I have a doozy for you guys. First of all, I didn't set up ANY of this system, I'm just working...
5
by: Jagadish Kumar, Maripi | last post by:
Hi, I got the following error while trying to compile php with mysql. I would be glad if anyone can help me on this. Here is the error that i've got in config.log The command i used is:...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.