php - 在没有mysqli_real_escape_string的情况下在数据库中用单引号保存字符串

标签 php mysql string mysqli

<分区>

我想在我的表列中保存字符串“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/

相关文章:

php - 在 PDO/MySQL 中获取同一行的下一列的下一个元素?

php - 为什么我有这个laravel错误?

php - 使用 ORDER BY 或 PHP 排序函数对 MySQL 查询进行排序

php - Google 驱动器分页不起作用。清空 nextPageToken

mysql - 同一行有多个匹配项

mysql - 同时使用MariaDB和mysql 5.7

javascript - 具有多个条件的字符串到字符串数组

java - 将字符串与 Java 中声明为 Final 的 == 进行比较

php - 从共享主机发送的电子邮件,已阻止。有没有办法避免这种情况?

c++ - 你如何打印 std::regex?