前几天我开发了一个带有mssql server数据库的PHP项目。现在我需要将MSSQL数据库更改为MySQL数据库。以前我使用过odbc_result
方法,但我将odbc的所有方法转换为mysqli过程的方法。所以我需要一个像odbc_result
一样的函数用于mysqli - 它是哪一个?我试图使用mysqli_result
,但它会抛出一个错误“调用未定义的函数mysqli_result()”。
下面我说明了这个功能:
function checkCountry($con)
{
if ($con != '') {
$cCodeList = array();
$i = 0;
$checkCountrySql = "SELECT country_code FROM country";
$checkCountyResult = mysqli_query($con, $checkCountrySql);
while (mysqli_fetch_row($checkCountyResult)) {
for ($j = 1; $j <= mysqli_num_fields($checkCountyResult); $j++) {
$ar = mysqli_result($checkCountyResult, $j);
}
$cCodeList[$i] = $ar;
$i++;
}
return $cCodeList;
}
}
那么对于mysqli来说,odbc_result
的替代方法是什么?
答案 0 :(得分:1)
我正在尝试使用
mysqli_result
,但它发出错误“调用未定义的函数mysqli_result()”。
因为mysqli_result()
中没有MySQLi
功能。
现在看看for
循环,你在循环的每次迭代中覆盖$ar
。实际上,您根本不需要这个for
循环,只需按以下方式更改while
循环,
while ($row = mysqli_fetch_row($checkCountyResult)) {
$cCodeList[] = $row;
}