the @ character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

the @ character

Post by malcolmboston »

ive searched for this in the manual after seeing a script using this last night

Code: Select all

@mysql_query
i havent got a clue what it is for, am just wondering as the manual doesnt say

Thanks
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

It supresses error messages
This will supress the injection of error messages into the data stream output to the web client. You might do this, for example, to supress the display of error messages were foo() a database function and the database server was down. However, you're probably better off using php configuration directives or error handling functions than using this feature.
See the section on error handling functions.

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok but on my dbhandler.php (included in every page) page i have

Code: Select all

error_reporting(0)
does this negate the need for @ or does it stop different sorts of error messages?

Thanks as usual bech
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

@ is good for running a function within an if statement so you can get your own custom error sequence. That's the way I mainly use it.

ex.

Code: Select all

<?php
if (@mysql_query($q))
{
  // do whatever
} else {
  // alert admin via email, insert count into textfile, etc, etc..
}
?>
So to answer your question, in a more direct way, no. The script has that for a reason and to remove it would undermind that reason. :) I'd just keep it there.
Post Reply