Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysqli_real_escape_string not safe ? #7

Open
olypros opened this issue Jan 19, 2017 · 3 comments
Open

mysqli_real_escape_string not safe ? #7

olypros opened this issue Jan 19, 2017 · 3 comments

Comments

@olypros
Copy link

olypros commented Jan 19, 2017

i know mysql_real_escape_string is not safe

But the mysqli safe ? (improved version ).

Give me one example that will get around this ?
$id = mysqli_real_escape_string($con,htmlentities(trim($id)));
"SELECT * from table where id = '$id' "

@mrivanova
Copy link

mrivanova commented Jan 20, 2017

Hi :)

"But the mysqli safe ?"
mysqli_real_escape_string can be circumvented, but only in very obscure situations (not likely to apply to you or most everyone else).

More info in this answer: http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string/12118602#12118602

so never set charset with a query like this one 'SET NAMES {charset}'
Use mysqli_set_charset or mysqli_options($link, MYSQLI_SET_CHARSET_NAME, "{charset}");

@laurent22
Copy link
Owner

There's also the issue of long term maintenance. If you use concatenated queries, even if correctly escaped, future developers are more likely to make mistakes. There's a discussion about it there: #3

@olypros
Copy link
Author

olypros commented Jan 20, 2017

yeah apart from maintenance . Technically there is no security flaws in between mysqli (not mysql) and prepared statements i think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants