Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/214714-mysql_connect-general-question/
Share on other sites

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();
}

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.