<分区>
我想在我的表列中保存字符串“thats'one”,但我不想使用 mysqli_real_escape_string
。谁能指导我如何做到这一点?
<分区>
我想在我的表列中保存字符串“thats'one”,但我不想使用 mysqli_real_escape_string
。谁能指导我如何做到这一点?
最佳答案
因为我在这里看到这么多低质量的评论,这里是一个粗略的未经测试的答案。
$query = "INSERT INTO table (Column) VALUES (?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $val1);
$val1 = "thats'one";
$stmt->execute();
这假定 $mysqli
是您的连接对象。
关于该主题的其他链接:
http://php.net/manual/en/mysqli-stmt.execute.php
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet#Defense_Option_1:_Prepared_Statements_.28Parameterized_Queries.29
http://php.net/manual/en/security.database.sql-injection.php
How can I prevent SQL injection in PHP?
关于php - 在没有mysqli_real_escape_string的情况下在数据库中用单引号保存字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34542664/