我正在尝试将旧网站转换为使用mysqli而不是mysql。
使用此部分代码
命中一个小块if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
我不断收到错误
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in
如果我添加这样的连接
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($test,$theValue) : mysqli_escape_string($test,$theValue);
得到错误
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given
有人可以告诉我我做错了吗
非常感谢
答案 0 :(得分:5)
答案 1 :(得分:0)
mysqli_real_escape_string也需要传递数据库连接。所以你需要将它提供给函数,然后执行:
mysqli_escape_string($connection, $theValue);
http://php.net/manual/en/mysqli.real-escape-string.php
此外,它会告诉您$test
变量为null
- 再次,它期望您使用myqli_connect()
创建的实时数据库连接。您可能需要将其作为参数传递给函数。