警告:mysqli::query():在C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\my portable files\class_EventCalendar.php的第43行无法获取mysqli。以下是我的连接文件:
这是我的班级:
我对面向对象的PHP不太擅长,也不确定为什么会出现这个错误。我从其他地方复制了这段代码,唯一改变的是
在PHP 8上执行相同的操作时,我发现了一个类似的错误,错误信息如下:
<?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);
我对面向对象的PHP不太擅长,也不确定为什么会出现这个错误。我从其他地方复制了这段代码,唯一改变的是
@new mysqli
的参数。有人能帮我理解出了什么问题吗?在PHP 8上执行相同的操作时,我发现了一个类似的错误,错误信息如下:
未捕获的错误:mysqli对象已关闭
$DBConnect = @new mysqli("localhost","root","","Ladle");
- Aycan Yaşıtnew mysqli()
时,为什么要使用@
来抑制错误? - Gottlieb Notschnabel