【发布时间】:2014-07-25 19:31:09
【问题描述】:
以下代码给了我这个错误:
在第 21 行调用未定义的方法 mysqli_stmt::get_result()。
我不明白这个对象是如何工作的,为什么我可以进行第一次数据库调用但不能进行第二次。
<?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);
?>
【问题讨论】:
-
请指定哪一行是21??你怎么知道第一个mysqli调用没问题?
-
我不知道您的问题的答案,但我始终发现了解某事的工作原理通常是最重要的一步。看到这条评论:stackoverflow.com/a/8343970/1888402 另外,不要害羞,这是一个公共论坛,人们喜欢通过帮助别人获得积分,所以这对所有参与者来说都是双赢的。
-
一个问题是你的第一个查询 call 是 Mysql reserved keyword 你需要用 bact-ticks 转义它
-
如上所述,
call是保留字。使用反引号`或将其重命名为calls。可以很好地解决问题。