Php mysqli_real_escape_string()正好需要2个参数,1个给定

Php mysqli_real_escape_string()正好需要2个参数,1个给定,php,mysqli,Php,Mysqli,mysqli\u real\u escape\u string的所有文档似乎都表明这是一段有效的代码,但我不明白为什么会出现此错误: mysqli_real_escape_string()正好需要2个参数,1个给定 表示它需要两个参数: if (phpversion() >= '4.3.0'){ $string = mysqli_real_escape_string($string); }else{ $string = mysqli_escape_string($strin

mysqli\u real\u escape\u string
的所有文档似乎都表明这是一段有效的代码,但我不明白为什么会出现此错误:

mysqli_real_escape_string()正好需要2个参数,1个给定

表示它需要两个参数:

if (phpversion() >= '4.3.0'){
    $string = mysqli_real_escape_string($string);
}else{
    $string = mysqli_escape_string($string);
}

第一个是mysqli实例的链接,第二个是要转义的字符串。

以下是使用它的正确格式:

string mysqli_real_escape_string ( mysqli $link , string $escapestr )
第一个参数是mysql连接链接标识符,第二个参数是字符串
有关详细信息,您可以访问以下链接:

让我再补充一点信息: 如果您使用的是NetBeans,它的文档实际上会显示mysqli_real_escape_字符串 功能如下:

string mysqli_real_escape_string ( mysqli $link , string $escapestr )
但是,正如其他答案所示,这是错误的。它需要$link和$string。

mysqli\u real\u escape\u string(DBconnection,\uuuu dat\uu a);
mysqli_real_escape_string (PHP 5)
    Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection

Parameters:

    string $escapestr
        'The string to be escaped.'

Returns:

    Type:
    string

Description:
    an escaped string.

mysqli_real_escape_string需要db connection变量

您确定要阅读的是
mysqli_real_escape_string
而不是
mysql_real_escape_string
的文档吗?特别是当PHP 5之前不存在
mysqli
函数时……您知道我该怎么做吗?这样netbeans自动完成功能将显示
mysqli\u real\u escape\u字符串($link,$escapestr)
而不是
mysqli\u real\u escape\u字符串($escapestr)
?关闭netbeans。转到:
\php\phpstubs\phpruntime
编辑文件
mysqli.php
,按
CTRL
+
F
并搜索
mysqli\u real\u escape\u字符串
。在
$escapestr
之前添加
$link
参数,并在上面的注释部分,在
*@param mysqli$link
之前的行中添加
*@param string$escapestr
。打开Netbeans并对其进行测试。注意:您可能必须在具有管理员权限的编辑器中打开该文件,或者将其复制到桌面,在那里进行编辑,然后将其复制/替换回原始文件夹。4年后,Netbeans文档仍然存在缺陷。
$con = new mysqli("localhost", "root", "your_password", "your_database_name");
$data = json_decode(file_get_contents("php://input"));
$empno = mysqli_real_escape_string($con, $data->empno);//this will do your work