Jump to content

mysql real escape


the-botman

Recommended Posts

See Example 1 at the php.net link that shlumph posted.

 

The most general purpose way is to use sprintf since it separates the php syntax as much as possible from the sql syntax. It's also very similar to how you would form a query using prepared statements, so when you are ready to move onto that step, things will already look familiar.

Link to comment
https://forums.phpfreaks.com/topic/268381-mysql-real-escape/#findComment-1378080
Share on other sites

As @PFMaBiSmAd mentioned above using sprintf - http://en.wikipedia.org/wiki/SQL_injection (take a look at Escaping )

Example:

$query = sprintf("SELECT * FROM `Users` WHERE UserName='%s' AND Password='%s'",
                  mysql_real_escape_string($Username),
                  mysql_real_escape_string($Password));
mysql_query($query);

 

Best way to prevent SQL injection is prepared statements and parametrical queries, using PDO or mysqli.

Link to comment
https://forums.phpfreaks.com/topic/268381-mysql-real-escape/#findComment-1378560
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.