调用未定义的函数mysqli_stmt_get_result()

时间:2018-04-26 00:09:03

标签: php mysqli

我正在努力弄清楚为什么这段代码会返回此错误:

  

在第46行的_____中调用未定义的函数mysqli_stmt_get_result()

此代码在我的本地计算机上使用XAMPP正常运行,但是当我将其上传到我的webhost时却没有。在我的webhost上,我正在运行 PHP版本5.5.38 ,在我的本地计算机上运行 PHP版本5.6.34 。有什么建议?我试图在这里查看其他线索以找出问题所在,但到目前为止我没有太多运气。我有mysqlnd驱动程序......

有问题的行是直接在错误检查下的行,如下所示:

  

$ result = mysqli_stmt_get_result($ stmt);

<?php
ini_set('display_errors', '1');error_reporting(E_ALL);

session_start();


if(isset($_POST['submit'])){
	include 'dbh.inc.php';

	$username = mysqli_real_escape_string($conn, $_POST['username']);
	$pass = mysqli_real_escape_string($conn, $_POST['password']);


	if(empty($username) || empty($pass)){
		header('Location:../login.php?login=empty');
		exit();
	} else {
		$sql = "SELECT * FROM users WHERE username = ?";
		$stmt = mysqli_stmt_init($conn);

		if (mysqli_stmt_prepare($stmt,  $sql) === false) {
		    trigger_error("Prep Error: " . mysqli_error($conn));
		    
		}
		if (mysqli_stmt_bind_param($stmt, "s", $username) === false) {
		    trigger_error("Bind Error: " . mysqli_stmt_error($stmt));
		    
		}
		if (mysqli_stmt_execute($stmt) === false) {
		    trigger_error("Execute Error: " . mysqli_stmt_error($stmt));
		    
		}
		$result = mysqli_stmt_get_result($stmt);
		$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);

		$num_rows = count($rows);

		if($num_rows < 1){
			header('Location:../login.php?login=error');
			exit();
		} else {
			foreach ($rows as $row) {

				$hashedPwdCheck = password_verify($pass, $row['user_pass']);
				if($hashedPwdCheck == false){
					header('Location:../login.php?login=ipass');
					exit();
				} elseif ($hashedPwdCheck == true) {
					session_regenerate_id(true);

					$_SESSION['user_id'] = $row['user_id'];
					$_SESSION['username'] = $row['username'];
					$_SESSION['first_name'] = $row['user_first'];
					$_SESSION['last_name'] = $row['user_last'];
					$_SESSION['user_email'] = $row['user_email'];
					header('Location:../index.php?login=success');
					exit();
				}
			}
		}
	}

} else {
	header('Location:../index.php?login=error');
	exit();
}

0 个答案:

没有答案