- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个小问题。当我尝试登录我编写的脚本时,我无法登录。我希望你们能帮助我。由于某种原因,我收到此 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
函数代替此函数。
有用的链接
关于javascript - 调用第 43 行未定义的方法 mysqli_stmt::get_result(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41841523/
我在尝试修改某些表时不断收到此错误。这是我的代码: /** = 1){ //$this->mysqli->autocommit(FALSE); //insert th
这是我的代码...它是关于使用 php mysqli 扩展 connect_errno) { die('Unable to connect to database'); } mysqli_se
这个问题已经有答案了: Catchable fatal error: Object of class mysqli_stmt could not be converted to string (2 个
我在向 MySQL 中插入数据时遇到问题。这是错误,我找不到解决方案。phpmyadmin 阵营和某些名称在 : PHPMYADMIN - 名称: 电子邮件 -> 电子邮件 密码 -> pass1 n
我正在使用 mysqli 类和准备好的语句在 PHP 中编写一个数据库处理程序类。我试图打印出结果。它并没有立即起作用,所以我决定进行一些调试。我尝试使用 mysqli_statement 类中的 n
我正在尝试将日期字段添加到源并保存到 PHP/MySQL 数据库。我正在使用 phpMyAdmin 并将“edate”字段设置为“DATE”类型。 我保存数据的 PHP 文件是: $statement
这是我的登录PHP代码 prepare($sql); $stmt->bind_param("s",$user_uid); $stmt->execute();
我很难理解如何正确使用bindParam(); 我一直在关注以下 URL 的详细信息:http://php.net/manual/en/pdo.prepared-statements.php其中的示例
这是我的代码: include 'conn.php'; $conn = new Connection(); $query = 'SELECT EmailVerified, Blocked FROM u
这个问题已经有答案了: warning :: invalid object or resource mysqli_stmt. What is the meaning and solution(s)?
我正在创建一个用户注册系统,当我开始修改数据库时出现错误“警告:mysqli_stmt::bind_param():类型定义字符串中的元素数量与第 41 行/opt/lampp/htdocs/Proj
这个问题已经有答案了: Call to undefined method mysqli_stmt::get_result (10 个回答) 已关闭 9 年前。 我正在将所有脚本更改为使用 mysqli
所以,我目前正在尝试为我的浏览器游戏创建一个登录表单,这需要多个查询才能正常工作。我首先开始使用 PHP 和 MySQL 进行查询的正常过程,但很快发现由于 SQL 注入(inject),这并不是最好
这是我的代码: include 'conn.php'; $conn = new Connection(); $query = 'SELECT EmailVerified, Blocked FROM u
这是我的代码: include 'conn.php'; $conn = new Connection(); $query = 'SELECT EmailVerified, Blocked FROM u
这个问题在这里已经有了答案: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in
这是我的代码: include 'conn.php'; $conn = new Connection(); $query = 'SELECT EmailVerified, Blocked FROM u
我试图将可变数量的参数传递给类的方法。这是我试图调用的类的函数: class DbHelper{ .... public function Execute($query, $params){
下面的代码抛出了神秘的警告。我不明白他们的意思。这些错误表明什么以及如何消除它们? require "conn.php"; $q = mysqli_stmt_init($dbconn); $query
我正在构建一个简单的留言板,需要从 3 个不同的表中获取信息来显示主要摘要页面。我正在使用 mysqli_stmt 协议(protocol),无法弄清楚如何获取每个讨论的第一条消息和作者姓名,因为所有
我是一名优秀的程序员,十分优秀!