gpt4 book ai didi

javascript - 调用第 43 行未定义的方法 mysqli_stmt::get_result()

转载 作者:行者123 更新时间:2023-11-29 19:30:10 30 4
gpt4 key购买 nike

我有一个小问题。当我尝试登录我编写的脚本时,我无法登录。我希望你们能帮助我。由于某种原因,我收到此 MySQL 错误:

Call to undefined method mysqli_stmt::get_result() in home/[username]/public_html/inc/session.php on line 43

session.php 的代码:

<?php

class Session {
private $self_file = 'session.php';
private $mysqli = false;

public function __construct($m) { $this->mysqli = $m; }

public function isLogged() {
if(!isset($_SESSION['invento_logged']) || !is_array($_SESSION['invento_logged']))
return false;

if(!isset($_SESSION['invento_logged']['u']) || !isset($_SESSION['invento_logged']['p']))
return false;

$u = $_SESSION['invento_logged']['u'];
$p = $_SESSION['invento_logged']['p'];

$prepared = $this->prepare("SELECT count(*) as c FROM invento_users WHERE username=? && password=?", 'isLogged()');
$this->bind_param($prepared->bind_param('ss', $u, $p), 'isLogged()');
$this->execute($prepared, 'isLogged()');

$result = $prepared->get_result();
$row = $result->fetch_object();

if($row->c == 1)
return true;
return false;
}

public function refresh_password($pass) {
$_SESSION['invento_logged']['p'] = md5($pass);
return true;
}

public function login($u, $p) {
$p = md5($p);

$prepared = $this->prepare("SELECT count(*) as c FROM invento_users WHERE username=? && password=?", 'isLogged()');
$this->bind_param($prepared->bind_param('ss', $u, $p), 'login()');
$this->execute($prepared, 'login()');

$result = $prepared->get_result();
$row = $result->fetch_object();

if($row->c != 1)
return false;

$_SESSION['invento_logged']['u'] = $u;
$_SESSION['invento_logged']['p'] = $p;

return true;
}

public function logout() {
if(isset($_SESSION['invento_logged']))
$_SESSION['invento_logged'] = false;
unset($_SESSION);
session_destroy();
return true;
}

public function get_user_id() {
$username = $_SESSION['invento_logged']['u'];

$prepared = $this->prepare("SELECT id FROM invento_users WHERE username=?", 'get_user_id()');
$this->bind_param($prepared->bind_param('s', $username), 'get_user_id()');
$this->execute($prepared, 'get_user_id()');

$result = $prepared->get_result();
$row = $result->fetch_object();

return $row->id;
}

public function get_user_name_by_id($id) {
$prepared = $this->prepare("SELECT username FROM invento_users WHERE id=?", 'get_user_name_by_id()');
$this->bind_param($prepared->bind_param('i', $id), 'get_user_name_by_id()');
$this->execute($prepared, 'get_user_name_by_id()');

$result = $prepared->get_result();
$row = $result->fetch_object();

return $row->username;
}

public function get_user_role() {
$id = $this->get_user_id();

$prepared = $this->prepare("SELECT role FROM invento_users WHERE id=?", 'get_user_role()');
$this->bind_param($prepared->bind_param('i', $id), 'get_user_role()');
$this->execute($prepared, 'get_user_role()');

$result = $prepared->get_result();
$row = $result->fetch_object();

return $row->role;
}


/***
* Private functions
*
***/
private function prepare($query, $func) {
$prepared = $this->mysqli->prepare($query);
if(!$prepared)
die("Couldn't prepare query. inc/{$this->self_file} - $func");
return $prepared;
}
private function bind_param($param, $func) {
if(!$param)
die("Couldn't bind parameters. inc/{$this->self_file} - $func");
return $param;
}
private function execute($prepared, $func) {
$exec = $prepared->execute();
if(!$exec)
die("Couldn't execute query. inc/{$this->self_file} - $func");
return $exec;
}
private function query($query, $func) {
$q = $this->mysqli->query($query);
if(!$q)
die("Couldn't run query. inc/{$this->self_file} - $func");
return $q;
}
public function __destruct() {
if(is_resource($this->mysqli) && get_resource_type($this->mysqli) == 'mysql link')
$this->mysqli->close();
}
}

$_session = new Session($mysqli);

和 config.php 的代码:

<?php
session_start();

/************ You can edit details starting from here ************/
$dbhost = '(I've filled this in'; // Write your MySQL host here.
$dbuser = 'I've filled this in'; // Write your MySQL User here.
$dbpass = 'I've filled this in'; // Write your MySQL Password here.
$dbname = 'I've filled this in'; // Write the MySQL Database where you want to install


/************ DON'T EDIT NOTHING BELOW ************/




if(!isset($noredir) && $dbhost == 'localhost' && $dbuser == 'MYSQL USERNAME' && $dbpass == 'MYSQL PASSWORD')
header('Location:install.php');
if(!isset($noredir)) {
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($mysqli->connect_errno)
die('<h2>Something went wrong while trying to connect to your MySQL Database. Error No. ' . $mysql->connect_errno.'<h2>');

// Check existance of random table to test installed system
$tables = array('users','categories','items','logs','settings');
$rn = rand(0,4);
$res = $mysqli->query("SHOW TABLES LIKE '%invento_{$tables[$rn]}%'");
if($res->num_rows == 0)
header('Location:install.php');
}

希望大家能帮帮我。提前致谢,

布拉姆

最佳答案

我认为这是因为您使用的 PHP 版本所致。

正如 php 文档 mysqli_stmt::get_result 中提到的,从 PHP 5.3.0 开始支持此方法。

用户注释部分指出:

此方法需要 mysqlnd 驱动程序。否则你会得到这个错误:Call to undefined method mysqli_stmt::get_result()

尝试使用 bind_result 函数代替此函数。

有用的链接

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

关于javascript - 调用第 43 行未定义的方法 mysqli_stmt::get_result(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41841523/

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