我正在使用webstera cpanel来托管我的Web应用程序,这是我的代码,我正在使用会话登录
致命错误:未捕获错误:在null上调用成员函数query() 在/home/buddhika/public_html/login.php:38堆栈跟踪:#0 {main} 在第38行的/home/buddhika/public_html/login.php中引用
<?php
@ob_start();
session_start();
?>
<html>
<head>
<?php
include_once('php/db-connect.php');
$error = "";
$msg = "";
if (isset($_SESSION["isLoggedIn"])) {
header("Location: index.php");
}
global $sql;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "SELECT fname, password FROM login";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
if (($_POST["username"] == $row["fname"]) && (($_POST["pass"]) == $row["password"])) {
header("Location: index.php");
$_SESSION["isLoggedIn"] = true;
$_SESSION["username"] = $row["fname"];
$_SESSION["image"] = $row["adimage"];
//alert();
$msg = "login success.";
} else {
$error = "Enter a valid username/password !!!";
}
}
}
}
db connection class
<?php
class Db {
// The database connection
protected static $connection;
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect() {
// Try and connect to the database
if(!isset(self::$connection)) {
// Load configuration as an array. Use the actual location of your configuration file
$config = parse_ini_file('./config.ini');
self::$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']);
}
// If connection was not successful, handle the error
if(self::$connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
return self::$connection;
}
public function query($query) {
// Connect to the database
$connection = $this -> connect();
// Query the database
$result = $connection -> query($query);
return $result;
}
答案 0 :(得分:0)
&#34;非对象&#34;表示变量(Dim CallingWb As Workbook
Set CallingWb = Application.Caller.Parent.Parent
)没有引用对象。您是否已将其分配给您的数据库类(例如,$conn
;或者您所使用的任何类已被命名)?