本文介绍了mysqli :: query():无法获取mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述以下是我的连接文件:<?phpif(!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参数.谁能帮助我了解问题出在哪里?I'm not great with OOP PHP and I'm not sure why this error is being raised. I pulled this code from elsewhere and the only thing I changed was the @new mysqli parameters. Can anyone help me to understand what is going wrong?推荐答案可能是您有 DBconnection->close(); 的某个地方,然后某些查询尝试执行.Probably somewhere you have DBconnection->close(); and then some queries try to execute . 提示:有时在 __destruct() 中插入 ...->close(); 有时会出错(因为__destruct是事件,此后会出现需要执行查询)Hint: It's sometimes mistake to insert ...->close(); in __destruct() (because __destruct is event, after which there will be a need for execution of queries) 这篇关于mysqli :: query():无法获取mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-12 13:30