资源 ID#5 PHP MySQL 错误 [英] Resource ID#5 PHP MySQL Error
本文介绍了资源 ID#5 PHP MySQL 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
<?php
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $con);
$result = mysql_query("SELECT SUM(colname) FROM profits");
$total = reset (mysql_fetch_assoc($result));
mysql_close($con);
echo $total;
?>
它输出一个资源 ID #5.有什么帮助吗?提前致谢!
And its outputting an Resource id #5. Any help? Thanks in advance!
推荐答案
不要像那样使用 reset()
- 如果您需要单个值,只需使用 list()代码>:
Don't use reset()
like that - if you need a single value, just use list()
:
$result = mysql_query("SELECT SUM(colname) FROM profits");
list($total) = mysql_fetch_array($result);
reset()
在关联数组上无法按预期工作:https://bugs.php.net/bug.php?id=38478
reset()
does not work as you expect on associative arrays: https://bugs.php.net/bug.php?id=38478
这篇关于资源 ID#5 PHP MySQL 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文