警告:mysql_num_rows()期望参数1为资源,布尔值在 [英] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
问题描述
我得到此错误Warning: mysql_num_rows() expects parameter
1是资源,我的代码中给出的布尔值如下
这是第if(mysql_num_rows($res)>0){
行
请帮助我
I got this error Warning: mysql_num_rows() expects parameter
1 to be resource, boolean given in my code is below
and here it line if(mysql_num_rows($res)>0){
please help me
function getProgramFee(){
$sql = "SELECT program_merchantid,program_id,program_fee,program_value,program_type FROM partners_program";
$res = @mysql_query($sql);
if(mysql_num_rows($res)>0){
while($row = mysql_fetch_object($res)){
$merid = $row->program_merchantid;
$id = $row->program_id;
$prgm_fee = trim($row->program_fee);
$prgm_value = $row->program_value;
$prgm_type = $row->program_type;
if(($prgm_type == "0")){
$prgm_fee = $program_fee;
$prgm_value = $program_value;
$prgm_type = $program_type;
}
推荐答案
为布尔值的参数为$res
. mysql_query
发生错误时返回FALSE
:
The parameter that is a boolean is $res
. mysql_query
returns FALSE
on error:
对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回的语句 结果集,
mysql_query()
成功返回资源,或者FALSE
成功 错误.
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset,
mysql_query()
returns a resource on success, orFALSE
on error.
来自 http://php.net/manual/en/function.mysql -query.php .
问题是您的SQL查询无效,可能是因为partners_program
不存在,或者是因为其中一个字段不存在.
So the problem is that your SQL query is invalid, maybe because partners_program
doesn't exist or because one of the fields doesn't exist.
调试问题的一个好开始是删除mysql_query
前面的@
. @禁止显示所有错误,通常会皱眉.如果正确设置了PHP设置以进行调试,那么您应该会收到描述性错误消息.您也可以出于调试目的,在mysql_query
之后立即使用mysql_error()
以获得更多详细信息.
A good start in debugging the problem is to remove the @
in front of mysql_query
. The @ suppresses all errors and is generally frowned upon. If your PHP settings are properly set up for debugging, you should then receive a descriptive error message. You could also for debugging purposes use mysql_error()
right after the mysql_query
for more details.
此外,mysql_*
函数已经被弃用了很长时间,因此,如果可能的话,您应该改为使用pdo
或mysqli
库.
Also, mysql_*
functions has been deprecated for a long while now, so if it is possible, you should check out the pdo
or mysqli
libraries instead.
这篇关于警告:mysql_num_rows()期望参数1为资源,布尔值在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!