在没有mysqli_real_escape_string的数据库中使用单引号保存字符串

adn*_*lid 0 php mysql string mysqli

我想在我的表列中保存字符串"thats'one",但我不想使用mysqli_real_escape_string.任何人都可以指导我如何做到这一点?

chr*_*s85 5

由于我在这里看到如此多的低质量评论,这是一个粗略的未经测试的答案.

$query = "INSERT INTO table (Column) VALUES (?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $val1);
$val1 = "thats'one";
$stmt->execute();
Run Code Online (Sandbox Code Playgroud)

这假设$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
如何在PHP中阻止SQL注入?