mysqli_num_rows() 期望参数 1 是 mysqli_result,对象

mysqli_num_rows() expects parameter 1 to be mysqli_result, object(mysqli_num_rows() 期望参数 1 是 mysqli_result,对象)
本文介绍了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
",
    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,对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)