也许这个问题是重复的。但我找不到我的问题的答案。
我遇到了这个问题Fatal error: Call to undefined method mysqli_stmt::get_result() in demo.php on line 24
第24行位于代码$tasks = $stmt->get_result();
这是我的demo.php代码。
<?php
/**
* Class to handle all db operations
* This class will have CRUD methods for database tables
*
* @author Ravi Tamada
* @link URL Tutorial link
*/
class Demo {
private $conn;
function __construct() {
require_once dirname(__FILE__) . '/include/db_connect.php';
// opening db connection
$db = new DbConnect();
$this->conn = $db->connect();
}
public function getAllChatRooms() {
$stmt = $this->conn->prepare("SELECT * FROM chat_rooms");
$stmt->execute();
$tasks = $stmt->get_result();
$stmt->close();
return $tasks;
}
public function getAllUsers() {
$stmt = $this->conn->prepare("SELECT * FROM users");
$stmt->execute();
$tasks = $stmt->get_result();
$stmt->close();
return $tasks;
}
public function getDemoUser() {
$name = 'AndroidHive';
$email = 'admin@androidhive.info';
$stmt = $this->conn->prepare("SELECT user_id from users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
if ($num_rows > 0) {
$stmt->bind_result($user_id);
$stmt->fetch();
return $user_id;
} else {
$stmt = $this->conn->prepare("INSERT INTO users(name, email) values(?, ?)");
$stmt->bind_param("ss", $name, $email);
$result = $stmt->execute();
$user_id = $stmt->insert_id;
$stmt->close();
return $user_id;
}
}
}
?>
在我的index.php中,我有代码来调用该函数。 这是示例代码
<?php
$chatrooms = $demo->getAllChatRooms();
foreach ($chatrooms as $key => $chatroom) {
$cls = $key == 0 ? 'selected' : '';
?>
<li id="<?= $chatroom['chat_room_id'] ?>" class="<?= $cls ?>">
<label><?= $chatroom['name'] ?></label>
<span>topic_<?= $chatroom['chat_room_id'] ?></span>
</li>
<?php
}
?>
请帮我构建此代码。
谢谢。答案 0 :(得分:1)
您需要安装mysqlnd支持。 (MySQL本机驱动程序)