[英]Converting from php mysql to mysqli mysqli_fetch_array
I am in the middle of converting a program from the mysql library to mysqli. 我正在将程序从mysql库转换为mysqli。
Edit: Some more context 编辑:更多上下文
I have the following code calling a class 我有以下代码调用一个类
case "purchasing";
$tab = 'purchasing';
require $classes . 'purchasing.php';
$purchases = new Purchase_list($search_term, $scope);
require $templates . 'header.php';
require $templates . 'purchasing.php';
break;
The class that contains get_result below is Purchase_list Purchase list basically figures out what rows to retrieve from the database, runs a query and assigns the results to $this->result 下面包含get_result的类是Purchase_list Purchase list基本上可以确定要从数据库检索的行,运行查询并将结果分配给$ this-> result
That part is obviously working since I have a valid result. 由于我得到了有效的结果,因此该部分显然正在工作。 Then $templates .
然后$ templates。 'purchasing.php';
'purchasing.php'; displays those results.
显示这些结果。
For trouble shooting purposes purchasing.php only contains 为了解决问题,purchasing.php仅包含
while ($row = $purchases->get_result()) {
}
I have a function inside a class that looks like this 我在一个类中有一个函数,看起来像这样
function get_result() {
$results = mysqli_fetch_array($this->result);
if($results === FALSE) {
return false;
}else {
$results['OPENAMT'] = ($results['Puramt'] - $results['Recamt']);
return $results;
}
}
if I comment out the the $results['OPENAMT'] code everything works great, with that code not commented it times out the browser request. 如果我注释掉$ results ['OPENAMT']代码,则一切正常,如果未注释该代码,则会使浏览器请求超时。 This code worked with the mysql extension instead of mysqli
此代码与mysql扩展而不是mysqli一起使用
Can anyone shed any light on whats actually going on here. 任何人都可以阐明这里实际发生的一切。
a var_dump on $results before trying to return gives $ results上的var_dump,然后尝试返回给定
array(11) {
[0]=> string(5) "23074"
["Purno"]=> string(5) "23074"
[1]=> string(3) "AEC"
["Vendno"]=> string(3) "AEC"
[2]=> string(10) "11/28/2012"
["Purdate"]=> string(10) "11/28/2012"
[3]=> string(4) "0.00"
["Puramt"]=> string(4) "0.00"
[4]=> string(4) "0.00"
["Recamt"]=> string(4) "0.00"
["OPENAMT"]=> float(0)
}
I don't exactly know why you get this problem, but I hope this may help. 我不完全知道您为什么会遇到此问题,但我希望这会有所帮助。
Whereas mysql_fetch_array
returns FALSE
when there are no more rows to fetch, mysqli_fetch_arrays
returns NULL
. 当没有更多行
mysqli_fetch_arrays
时, mysql_fetch_array
返回FALSE
,而mysqli_fetch_arrays
返回NULL
。
So $results
is never === FALSE
, and you always get into the else
block and probably return some rubbish with warnings being fired. 因此
$results
永远不会=== FALSE
,并且您总是会进入else
块,并且可能会在发出警告的情况下返回一些垃圾。
As a consequence, the while
loop calling get_result()
never ends because instead of getting false
it gets I don't know what . 结果,调用
get_result()
的while
循环get_result()
因为它变得false
而不是获取, 我不知道是什么 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.