j.smith1981 Posted September 29, 2010 Share Posted September 29, 2010 Hi, I am really plugging into how to write functions in PHP. But I was going to delve into a user management program and try to create it, but dont want to be the older version of what I was before if you like, where I just type in for the sake of typing in code so I thought I would question what their doing. But a peice of code, a very small snippet, this came up: @mysql_connect What does this actually mean with the @ sign infront of the mysql_connect function? Seen this a few times but just never appreciated what the at sign means, any help is wonderfully appreciated of course. Thanks, Jeremy Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/ Share on other sites More sharing options...
trq Posted September 29, 2010 Share Posted September 29, 2010 It t is terror supressor and should be avoided. Use proper error trapping instead. Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117110 Share on other sites More sharing options...
JonnoTheDev Posted September 29, 2010 Share Posted September 29, 2010 What does this actually mean with the @ sign infront of the mysql_connect function? As Thorpe has stated, it supresses any errors that cause the script to exit or display a warning message. It can be used on any function. It should only be used if your script can still continue without the return result of the function. In your case this is a no, because if the function cannot connect to your database, no queries will run. So handle the errors as such: if(!$conn = mysql_connect(/*params here*/)) { // do something such as send an email, write to an error log, print a message to the screen. print "Could not connect to database, sorry about this."; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117119 Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2010 Share Posted September 29, 2010 Since display_errors should be off on a live server, there is no point in putting an @ in any code. Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117126 Share on other sites More sharing options...
j.smith1981 Posted September 29, 2010 Author Share Posted September 29, 2010 Ahh thats what it is! I just need to remove the @, brilliant. Will create some kind of exception then, really plugging into this all OOP related stuff, its making sense! Thanks for the speedy reply though! TBH I dont think that (with the tutorial I was looking at) tutorials that good, its got some stuf thats just pointless I think but its good to look at and expand on myself and make better, find my learning curve greatens and it allows me to learn a whole lot more! If that makes any sense lol. Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117149 Share on other sites More sharing options...
JonnoTheDev Posted September 29, 2010 Share Posted September 29, 2010 Since display_errors should be off on a live server, there is no point in putting an @ in any code. I dunno. I like to have control of when errors display or not so I usually set the option in a config file for each site. I usually have the php ini file set display_errors to on and then when I want them off, use an ini_set directive, error reporting level, in my website config file. I guess it doesn't matter which way round you do it, i.e keep display_errors to off in your ini file and then set them to on using ini_set. Just my preference. Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117157 Share on other sites More sharing options...
j.smith1981 Posted September 30, 2010 Author Share Posted September 30, 2010 Since display_errors should be off on a live server, there is no point in putting an @ in any code. I dunno. I like to have control of when errors display or not so I usually set the option in a config file for each site. I usually have the php ini file set display_errors to on and then when I want them off, use an ini_set directive, error reporting level, in my website config file. I guess it doesn't matter which way round you do it, i.e keep display_errors to off in your ini file and then set them to on using ini_set. Just my preference. I am personally too paranoid about securuty so I always have display errors set to off and then display all the errors of course in the http logs. Thats the way I usually do it. Quote Link to comment https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/#findComment-1117610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.