我想转换旧网站使用mysqli而不是mysql。从MYSQL转换到MYSQLI
撞了一下一个stumberling块与这部分代码
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);
连接GET错误
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
有人能告诉我什么,我做错了
非常感谢
错误消息告诉您确切* *什么是错的。如果你使用RTM,你可以看到这个函数有两个参数。你只提供一个。你错过了你的连接。 –
您必须将mysqli句柄传递给函数http://php.net/manual/en/mysqli.real-escape-string.php – Nicolai
您不需要测试'function_exists(“mysqli_real_escape_string”)''。如果mysqli存在,'mysqli_real_escape_string'也是如此。只需调用它。 – deceze