11

Which means, at the moment, are the safest for screening data in php to send them to the mysql database.

Thank, you )

frops
  • 2,056
  • 4
  • 28
  • 41

3 Answers3

16

I believe mysql_real_escape_string() mysqli_real_escape_string() is the best way to escape input data

Later edit since everything is deprecated now and information must be valid:

Try to use PDO as prepared statements are much safer or mysqli_*() functions if you really need to keep old code somewhat up-to-date.

Mihai Iorga
  • 38,217
  • 14
  • 107
  • 106
4

Currently the most preferred way to insure your safety is prepared statements.

example:

$preparedStatement = $db->prepare('SELECT * FROM memebers WHERE username = :username');

$preparedStatement->execute(array(':username' => $username));

$rows = $preparedStatement->fetchAll();

then when displaying your data use htmlspecialchars()

Songo
  • 5,433
  • 7
  • 55
  • 93
3
validMySQL($var) {
$var=stripslashes($var);
$var=htmlentities($var);
$var=strip_tags($var);
$var=mysql_real_escape_string($var);
return $var
}

The above code helps to sanitize most invalid data, just remember that you've to be connected to mysql database for mysql_real_escape_string to work...

user1260776
  • 316
  • 1
  • 2
  • 8