PHP 错误:Mysqli_real_escape_string() 需要 2 个参数,1 个给定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7743372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:17:59  来源:igfitidea点击:

PHP Error: Mysqli_real_escape_string() expects exactly 2 parameters, 1 given

phpmysql

提问by user880789

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

All the documentation for mysqli_real_escape_stringseems to indicate this is a valid bit of code - don't understand?

所有文档mysqli_real_escape_string似乎都表明这是一段有效的代码 - 不明白吗?

回答by meze

Documentationsaying two parameters: string mysqli_real_escape_string ( mysqli $link , string $escapestr ).

文档说两个参数:string mysqli_real_escape_string ( mysqli $link , string $escapestr ).

The first one is a link for a mysqli instance, the second one is the string to escape.

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

回答by Pedro Moreira

Let me just add an extra bit of information: If you are using NetBeans, its documentation actually shows the mysqli_real_escape_string function like this:

让我补充一点信息:如果您使用的是 NetBeans,它的文档实际上显示了 mysqli_real_escape_string 函数,如下所示:

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.

This is wrong, though, as shown in the other answers. It requires both the $link and the $string.

但是,如其他答案所示,这是错误的。它需要 $link 和 $string。

回答by Israel Meshileya

$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

回答by Nishu Tayal

Following is the proper format to use it :

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

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

first parameter is mysql connection link identifier, and second is string For more details, you can visit this link : http://in2.php.net/manual/en/mysqli.real-escape-string.php.

第一个参数是 mysql 连接链接标识符,第二个参数是 string 详细信息可以访问这个链接:http: //in2.php.net/manual/en/mysqli.real-escape-string.php

回答by learningjoe

mysqli_real_escape_string(DBconnection, __dat__a); mysqli_real_escape_string needs the db connection variable

mysqli_real_escape_string( DBconnection, __dat__a); mysqli_real_escape_string 需要数据库连接变量