三个函数:
addslashes($string);//用反斜线引用字符串中的特殊字符' " \
$username=addslashes($username);
mysql_escape_string($string);//用反斜杠转义字符串中的特殊字符,用于mysql_query()查询。
$username=mysql_escape_string($username);
mysql_real_escape_string($string);//转义SQL语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集,需要保证当前是连接状态才能用该函数,否则会报警告。 不转义%与_
$username=mysql_real_escape_string($username);
两种选择:一种是pdo,另一种是mysqli。
使用PDO
$stmt = $pdo->prepare('SELECT * FROM user WHERE name = :name');
$stmt->execute(array(':name' => $name));
foreach ($stmt as $row) {
// do something with $row
}
使用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防止sql注入
最新评论
Forex wiki. https://lt.forex-stock-bitcoin-brokers.com
Magnificent items from you, man. I have take note your stuff
Following on from the 3rd March Meetings held by economic de
It is remarkable, rather valuable message dfgdlfg2131.32
一般都会有一个沙盒期的,过了沙盒期就会慢慢放出来
百度不收录是应为是新站的原因吗?
The spike in consumer prices that left inflation at a four-d