我试图更新到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);
?>
3条答案
按热度按时间alen0pnh1#
你需要将所有的mysql_改为mysqli_,并添加到数据库的连接作为第一个参数。在我的例子中,到数据库的连接是**$conn_vote**。请注意,我添加了$conn_vote作为函数的参数:
hc8w905p2#
这为我工作'$config'作为dbase连接!
sprintf(INSERT或Update)使用:GetSQLValueString($config,$_POST['fname'],“text”)
p3rjfoxz3#
我也面临着同样的问题,我发现更合适的方法是摆脱这个函数,使用
mysqli_real_escape_string
,你可以像这样传递数据: