我试图更新到mysqli,我几乎更新了整个网站,但我遇到了GetSQLValueString的问题。如何将其更改为与mysqli兼容或必要时删除/更改。
<?php
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("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_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;
}
}
$colname_Recordset1 = "-1";
if (isset($_GET['stid'])) {
$colname_Recordset1 = $_GET['stid'];
}
mysqli_select_db( $SIS,$database_SIS);
$query_Recordset1 = sprintf("SELECT * FROM payments WHERE stid = %s",
GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysqli_query($SIS, $query_Recordset1) or die(mysqli_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
?>
答案 0 :(得分:0)
您需要将所有 mysql _ 更改为 mysqli _ ,并将连接添加到数据库作为第一个参数。在我的例子中,与数据库的连接是 $ conn_vote 。请注意,我添加了$ conn_vote作为函数的参数:
function GetSQLValueString($conn_vote, $theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conn_vote, $theValue) :
mysqli_escape_string($conn_vote, $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;
}
}
答案 1 :(得分:-1)
我面临着同样的问题,我发现更适合于摆脱该功能并使用mysqli_real_escape_string
来传递数据,如下所示:
mysqli_real_escape_string($GLOBALS["___mysqli_ston"], md5($password))