最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php mysql_real_escape_string()函数
时间:2022-06-24 19:02:47 编辑:袖梨 来源:一聚教程网
mysql教程_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
下列字符受影响:
x00
n
r
'
"
x1a
如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
语法
mysql_real_escape_string(string,connection)参数 描述
string 必需。规定要转义的字符串。
connection 可选。规定 MySQL 连接。如果未规定,则使用上一个连接。
实例
php教程
function opendatabase ($host,$user,$pass) {
try {
if ($db = mysql_connect ($host,$user,$pass)){
return $db;
} else {
throw new exception ("Sorry, could not connect to mysql.");
}
} catch (exception $e) {
echo $e->getmessage ();
}
}
function selectdb ($whichdb, $db){
try {
if (!mysql_select_db ($whichdb,$db)){
throw new exception ("Sorry, database could not be opened.");
}
} catch (exception $e) {
echo $e->getmessage();
}
}
function closedatabase ($db){
mysql_close ($db);
}
$db = opendatabase ("localhost","root","");
selectdb ("mydatabase",$db);
$_POST['user'] = "myname";
$_POST['pass'] = "mypassword";
function validatelogin ($user,$pass){
mysql_real_escape_string ($user);
mysql_real_escape_string ($pass);
$thequery = "SELECT * FROM userlogin WHERE username='$user' AND password='$pass'";
if ($aquery = mysql_query ($thequery)){
if (mysql_num_rows ($aquery) > 0){
return true;
} else {
return false;
}
} else {
echo mysql_error();
}
}
if (validatelogin ($_POST['user'],$_POST['pass'])){
echo "You have successfully logged in.";
} else {
echo "Sorry, you have an incorrect username and/or password.";
}
closedatabase ($db);
?>
相关文章
- 如鸢新活动游春集远房亲戚攻略 低配置无核爆通关攻略 08-03
- 燕云十六声免费外观攻略 最难拿到的三个免费套怎么拿 08-03
- 《弧光突袭者》 Arc Raiders “往昔药方”任务攻略 08-03
- 虚无世界宝宝技能搭配攻略(发掘宝宝技能的无限可能) 08-03
- 颠覆认知 曝PS6双机型定价悬殊 多数玩家恐难承受 08-03
- 《盾勇队长技能更换攻略》(优化战斗力,拓展战术选择,走上巅峰之路) 08-03