gpt4 book ai didi

php - mysqli::query(): 无法获取 mysqli

转载 作者:行者123 更新时间:2023-11-29 17:55:35 27 4
gpt4 key购买 nike

Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\my portable files\class_EventCalendar.php on line 43

以下是我的连接文件:

<?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 参数。谁能帮助我了解出了什么问题?

在 PHP 8 上执行相同的操作时,我可以观察到类似的错误:

Uncaught Error: mysqli object is already closed

最佳答案

可能在某个地方有DBconnection->close();,然后一些查询尝试执行。

<小时/>

提示:有时在 __destruct() 中插入 ...->close(); 是错误的(因为__destruct是事件,之后需要执行查询)

关于php - mysqli::query(): 无法获取 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48882528/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com