我想轉換舊網站使用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