gpt4 book ai didi

具有多个选择的 php sql 不起作用

转载 作者:行者123 更新时间:2023-11-30 00:01:52 26 4
gpt4 key购买 nike

以下代码给了我这个错误:

Call to undefined method mysqli_stmt::get_result() on line 21.

我不明白这个对象是如何工作的以及为什么我可以执行第一个数据库调用但不能执行第二个。

    <?php 

header('Content-Type: application/json');
include_once 'do_dbConnect.php';
include_once 'functions.php';
sec_session_start();

//identify who took the last call
$stmt = $mysqli->stmt_init();
if ($stmt->prepare("SELECT MAX(dateOfCall), id FROM call")) { //setup the query statement
$stmt->execute(); //execute the statement
$result = $stmt->get_result(); //get the results
$row = $result->fetch_assoc(); //get the first row
$user_id = $row['id']; //get the id column
}


//identify how many team members there are
if ($stmt->prepare("SELECT id FROM teamMembers")) { //setup the query statement
$stmt->execute(); //execute the statement
$result = $stmt->get_result(); //get the results
$memberCount = $result->num_rows;
}


//get next user
if ($stmt = $mysqli->prepare("SELECT * FROM teamMembers WHERE id = (? + 1) % ?")) { //setup the query statement
$stmt->bind_param('ii', $user_id, $memberCount);
$stmt->execute(); //execute the statement
$result = $stmt->get_result(); //get the results
$row = $result->fetch_assoc(); //get the first row
$next_user_id = $row['id']; //get the id column
$next_user_name = $row['username'];
}
$stmt->close();
//get the next call taker from the teamMember table

echo json_encode($row);

?>

最佳答案

请阅读此方法的用户说明:

http://php.net/manual/en/mysqli-stmt.get-result.php

它需要 mysqlnd 驱动程序...如果您的网站空间上没有安装它,您将必须使用 BIND_RESULT 和 FETCH!

http://www.php.net/manual/en/mysqli-stmt.bind-result.php

http://www.php.net/manual/en/mysqli-stmt.fetch.php

关于具有多个选择的 php sql 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24963211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com