Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use mysqli_real_escape_string or should I use prepared statements? [duplicate]

Should I use mysqli_real_escape_string or should I use prepared statements?

I've seen a tutorial now explaining prepared statements but I've seen them do the same thing as mysqli_real_escape_string but it uses more lines

Are there any benefits for prepared statements? What do you think is the best method to use?

like image 499
Ali Avatar asked Apr 03 '13 11:04

Ali


People also ask

When should I use mysqli_real_escape_string?

You should use real_escape_string on any parameter you're mixing as a string literal into the sql statement. And only on those string literal values.

Is mysqli_real_escape_string deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.

Does mysqli_real_escape_string prevent SQL injection?

PHP provides mysql_real_escape_string() to escape special characters in a string before sending a query to MySQL. This function was adopted by many to escape single quotes in strings and by the same occasion prevent SQL injection attacks. However, it can create serious security flaws when it is not used correctly.

What is the use of mysqli_real_escape_string () function?

The mysqli_real_escape_string() function is used to escape characters in a string, making it legal to use in an SQL statement.


1 Answers

Prepared statements only. Because nowhere escaping is the same thing. In fact, escaping has absolutely nothing to do with whatever injections, and shouldn't be used for protection.

While prepared statements offer the 100% security when applicable.

like image 168
Your Common Sense Avatar answered Sep 22 '22 09:09

Your Common Sense