我有一个疑问
$sql ="SELECT CustomerID FROM tblCustomer
WHERE EmailAddress = '".addslashes($_POST['username']) ."' AND Password = '".addslashes($_POST['password']) ."'";
// while printing, it will be
SELECT CustomerID FROM tblCustomer WHERE EmailAddress = 'test@ab\'c.com' AND Password = '123'
如果我们在 mysql 服务器中执行它,它可以工作,但在 sql 服务器中则不行
有什么解决办法吗?
。我正在使用 sql server
addslashes() http://www.php.net/manual/en/function.addslashes.php将使用前导反斜杠转义单引号,这在 MySQL 中是有效语法,但在 MS SQL Server 中无效。在 MS SQL Server 中转义单引号的正确方法是使用另一个单引号。使用mysql_real_escape_string() http://www.php.net/manual/en/function.mysql-real-escape-string.php对于 MySQL(mysql_escape_string() http://www.php.net/manual/en/function.mysql-escape-string.php已被弃用)。不幸的是,没有类似的mssql_
函数存在,因此您必须使用自己的函数str_replace() http://www.php.net/manual/en/function.str-replace.php, preg_replace() http://www.php.net/manual/en/function.preg-replace.php或类似的东西。更好的是,使用支持参数化查询的数据库中立抽象层,例如 PDO。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)