Jump to content

how to secure mysql_query()


orange08

Recommended Posts

 

thanks for the link, but i'm still not too understand...

 

$result = mysql_query('SELECT foo FROM bar', $db) or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR);

 

Syntactically this is very much like the previous code snippet, but much better. Because errors of these types behave like errors PHP would normally make you can also use all the facilities PHP has for error handling. You can implement a custom error handler so you can display nice messages to your user, and you can log the errors to a file. Finally you can disable output of errors in a production environment.

 

i would like to know for the above code, if error did occur...will the error message being output for the user?

 

and the above description saying that we can use all the facilities PHP has for error handling. we can implement a custom error handler so we can display nice messages to user, and we can log the errors to a file. Finally we can disable output of errors in a production environment.

 

but, how? i'm still not able to relate them...can give some example, please?

Link to comment
Share on other sites

sorry im having trouble understanding what you are asking :S please clarify.

 

errors can be controlled via the set_error_handler function

 

what i'm really confuse is what's the different between

or die(mysql_error());

and

or trigger_error('Query failed: '. mysql_error())

 

what i read before is

or die(mysql_error()) will remove the opportunity to control whether errors should be displayed or not.

i'm not too understand with this, is that meant if my error reporting set to off, then with or die(), mysql_error() still will be output for user that give a chance for hacker to know your site's problem?

 

and is that with

 

or trigger_error('Query failed: '. mysql_error())

then if my error reporting set to off, then the error won't be output for user when the error occur?

Link to comment
Share on other sites

I think that if error reporting is off, and you use trigger_error, then it doesn't show the error.

If error reporting is on, and you use trigger_error(), then it shows the error.

If you use die(), then it shows the error, even if error reporting is off.

 

Do you understand?

Link to comment
Share on other sites

I think that if error reporting is off, and you use trigger_error, then it doesn't show the error.

If error reporting is on, and you use trigger_error(), then it shows the error.

If you use die(), then it shows the error, even if error reporting is off.

 

Do you understand?

 

yup, this is what i understand, i tried to ask this question before, but seem nobody giving me an answer...

 

and if like that, if i'm set error reporting to off in production environment, then when some error occur, my user get nothing to inform them, right?

 

how should i code, so that mysql_error() which is can't be revealed to hacker won't be output but custom error message will be output for the user in case the sql query is failed?

Link to comment
Share on other sites

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.