Release Time:9 months agoHeat:816 ℃Number of comments:1
Three functions:
Addslashes ($string): Use a backslash to refer to a special character in a string ' "\
$username =addslashes ($username);
Mysql_escape_string ($string): Use backslashes to escape special characters in a string for mysql_query () queries.
$username =mysql_escape_string ($username);
Mysql_real_escape_string ($string): Escapes special characters in the string used in the SQL statement and takes into account the current character set of the connection to ensure that the function is currently connected, otherwise a warning is reported. Do not escape% with _
$username =mysql_real_escape_string ($username);
Two options:
Using PDO
$stmt = $pdo->prepare (' SELECT * from user WHERE name =: Name ');
$stmt->execute (Array (': Name ' = $name));
foreach ($stmt as $row) {
Do something with $row
}
Using mysqli
$stmt = $dbConnection->prepare (' SELECT * from user WHERE name =? ');
$stmt->bind_param (' s ', $name);
$stmt->execute ();
$result = $stmt->get_result ();
while ($row = $result->fetch_assoc ()) {
Do something with $row
}
PHP Prevents SQL injection