【问题标题】:PHP 7 mysqli_real_escape_string() Error [duplicate]PHP 7 mysqli_real_escape_string() 错误 [重复]
【发布时间】:2017-03-01 16:43:45
【问题描述】:

我最近将 php 5 更新为 php 7。所以当我运行项目时它会出现以下错误。

警告:mysqli_real_escape_string() 需要 2 个参数,1 个在 C:\xampp\htdocs\Project\Duplicate - Copy (2)\general.php 第 5 行中给出

这是代码。

<?php
function sanitize($data){   
    return mysqli_real_escape_string($data);
}
?>

然后我像这样重新编码连接。

$db = new PDO('mysql:host=localhost;dbname=test;charset=utf8mb4', 'root', "");

谁能帮帮我!

【问题讨论】:

  • 嗯.. 只需要 2 个参数,给定 1 个这告诉你什么?看说明书了吗???
  • 当我使用 php 5 版本时 .code 工作正常,但现在这样说
  • 你的意思是你在 php 5 中关闭了警告?
  • @Dasun 您不再使用 PHP5 和 mysql_*,因此请阅读 PHP7 的 mysqli_* 的文档,因为它们不同。旧的string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier = NULL ] ) 与新的string mysqli_real_escape_string ( mysqli $link , string $escapestr ) 不同是有原因的。
  • @jeroen 这可能是从mysql_*mysqli_* 的迁移工作

标签: php warnings php-7


【解决方案1】:

read the documentation了吗?

第一个参数需要是你的连接对象。

然而,你似乎也在混合和匹配 PDO 和 mysqli 函数。

二选一。

【讨论】:

    猜你喜欢
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 2015-11-07
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多