警告: mysqli::query():无法在第43行的C:\Program (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\my便携files\class_EventCalendar.php中获取mysqli
以下是我的连接文件:
<?php
if(!isset($_SESSION))
{
session_start();
}
// Create array to hold error messages (if any)
$ErrorMsgs = array();
// Create new mysql connection object
$DBConnect = @new mysqli("localhost","root@localhost",
NULL,"Ladle");
// Check to see if connection errno data member is not 0 (indicating an error)
if ($DBConnect->connect_errno) {
// Add error to errors array
$ErrorMsgs[]="The database server is not available.".
" Connect Error is ".$DBConnect->connect_errno." ".
$DBConnect->connect_error.".";
}
?>这是我的课:
<?php
class EventCalendar {
private $DBConnect = NULL;
function __construct() {
// Include the database connection data
include("inc_LadleDB.php");
$this->DBConnect = $DBConnect;
}
function __destruct() {
if (!$this->DBConnect->connect_error) {
$this->DBConnect->close();
}
}
function __wakeup() {
// Include the database connection data
include("inc_LadleDB.php");
$this->DBConnect = $DBConnect;
}
// Function to add events to Zodiac calendar
public function addEvent($Date, $Title, $Description) {
// Check to see if the required fields of Date and Title have been entered
if ((!empty($Date)) && (!empty($Title))) {
/* if all fields are complete then they are
inserted into the Zodiac event_calendar table */
$SQLString = "INSERT INTO tblSignUps".
" (EventDate, Title, Description) ".
" VALUES('$Date', '$Title', '".
$Description."')";
// Store query results in a variable
$QueryResult = $this->DBConnect->query($SQLString);我不太擅长OOP PHP,我也不知道为什么会引发这个错误。我从其他地方提取了这段代码,唯一改变的是@new mysqli参数。有人能帮我弄清楚到底出了什么问题吗?
发布于 2014-10-01 17:48:30
可能在您有DBconnection->close();的地方,然后一些查询尝试执行。
提示:在__destruct()中插入__destruct()有时是错误的(因为__destruct是事件,之后需要执行查询)
发布于 2013-11-12 19:39:38
错误的原因是mysqli对象初始化错误。真正的建筑应该是这样的:
$DBConnect = new mysqli("localhost","root","","Ladle");发布于 2018-04-29 07:49:38
我也有同样的问题。我将mysqli对象中的localhost参数更改为'127.0.0.1‘,而不是编写'localhost’。它起作用了,我不知道它是怎么起作用的,也不知道为什么。
$db_connection = new mysqli("127.0.0.1","root","","db_name");https://stackoverflow.com/questions/19937880
复制相似问题