mysqli_num_rows()期望参数1为mysqli_result,对象 [英] mysqli_num_rows() expects parameter 1 to be mysqli_result, object

查看:89
本文介绍了mysqli_num_rows()期望参数1为mysqli_result,对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用mysqli.似乎在mysqli_num_rows()的括号之间寻找结果集的名称.但是,当我尝试$ stmt,$ conn却一无所获时,我遇到了相同的错误.令人沮丧! $ WHAT在下面的最后一行中会怎样显示?

This is my first experience with mysqli. It seems to be looking for the name of a result set in between the parentheses in mysqli_num_rows(). Yet when I tried $stmt, $conn, and nothing, I got the same error. Frustrating! What goes where $WHAT is in the last line below?

或者也许我正在尝试错误的方法.我要做的就是检查是否返回了结果.我真的不需要行数.我应该只对一条错误消息执行else语句吗?那是最好的方法吗?有没有编写一种函数来连接和接受查询及其参数的好方法?我为mysql写了一篇,但这是如此不同!我不希望重写数十个查询!

Or maybe I'm trying the wrong tack. All I want to do is check that a result was returned. I don't really need the number of rows. Should I just do an else statement with an error message? Is that the best way to do it? And is there a good way to write a function to connect and accept the query and it's parameters? I wrote one for mysql but this is so different! I'm not looking forward to rewriting dozens of queries!

$conn = mysqli_connect($host, $user, $pwd, $db,$port=$port_nbr); 

if ($mysqli_connect_errno) {
    printf("Connect failed: %s\n",
    mysqli_connect_error());
    exit;
}
if($stmt=$conn->prepare("SELECT id, name, status, type FROM organization")) {
    $stmt->execute();
    $stmt->bind_result($org_id, $orgname, $orgstatus, $orgtype);    
    $num=mysqli_num_rows($WHAT);
}

推荐答案

当您只想面向对象时,就将过程和面向对象的方法结合在一起.更改

You're combining procedural and object oriented approaches, when you only want object oriented. Change

$num=mysqli_num_rows($WHAT);

$num = $stmt->num_rows();

这篇关于mysqli_num_rows()期望参数1为mysqli_result,对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆