首页 > 语言 > PHP > 正文

mysql_escape_string()函数用法分析

2024-05-04 23:45:15
字体:
来源:转载
供稿:网友
这篇文章主要介绍了mysql_escape_string()函数用法,结合实例形式讲述了mysql_escape_string()函数的功能,并分析了mysql_escape_string的使用技巧与注意事项,需要的朋友可以参考下
 

本文实例讲述了mysql_escape_string()函数用法。分享给大家供大家参考,具体如下:

使用 mysql_escape_string() 对查询中有疑问的数据进行编码:

有一些数据例如:

char query(1024);sprintf (query, "select * from my_tbl where name = '%s'",name);

如果这个时候,name 中包含了如: "0'Malley,Brian" 这样的数据就会产生这样的查询语句: select * from my_tbl where name = '0'Malley,Brian' 这样就导致了错误的产生。

调用 mysql_escape_string() 的过程如下:

my $item = "aaa's bbb"my $escape_item = mysql_escape_string($item);

此时,escape_item 的内容是: aaa/'s bbb

PS:在PHP5.3中已经弃用该函数,因此仅对该函数有所了解即可,不推荐使用。



注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选