我有一个 PHP 应用程序,我从多个来源获取名字和姓氏(API、文件等)
假设我得到像 john'
, john"
这样的名称,如何将名称保存在数据库中,',"
可以在任何地方,问题是当我编写像
Insert into table values('".$a."');
因此,如果 $a 包含名称 John',则查询将变为 Insert into table Values('John'');
,这是错误的,(末尾为 2 ')
如何用 PHP 来满足这些场景?
最佳答案
$string=mysqli_real_escape_string($connection,$string);
This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to an escaped SQL string, taking into account the current character set of the connection.
<强> Reference
关于php - PHP 中的转义字符和保留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544803/