'@' symbol in front of mysql commands...Why?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

'@' symbol in front of mysql commands...Why?

Post by bwv2 »

I'm having some bug problems in my first php script. It's several thousand lines long, so I'll spare the copy and paste. I think I have traced some of my issues to not having the "@" symbol in front of some mysql calls, such as the following:

@mysql_query($sql, $conn);
and so on and so on.

My question is to the very nature of this lingo. What does the '@' symbol do? Is it always necessary? If not, then when is it needed? I look forward to hearing an answer to this evasive topic (you can't search for the "@" symbol on google. So it's evasive!).

Brad
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Putting the @ symbol in front of any built in php command (not just mysql functions) will squelch any error reporting it generates: if you call mysql_select_db("my_db",$some_connection) and $some_connection isn't valid, mysql_select_db() will generate a warning or fatal error (not sure which one). Putting an @ symbol in front of the function will shut it up.

You should never use the @ symbol to make your code 'work'. If a function is outputing an error, there's always a reason - your best bet is to fix it.

That said, there are times when you may be using a function in a condition, and don't care about any errors it could generate. That'd be an ideal place to use the @ symbol.

Make sense?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Post by bwv2 »

alas. I can see clearly now. That makes my life so much harder. Everything was just skippy when I could magically stop the flow of errors. Oh well, back to the drawing board. I have an idea, someone give me your email address, I'll send you 2,000 lines of code full of errors, you fix it and send it back. Sound chipper? Yeah, if only it were that easy...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ha ha - at least your joking. Not everyone is when they ask for free debugging of 2K lines of code 8O .
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply