問題描述
我有一段這樣的代碼:
$conn = new mysqli($host, $username, $passwd, $dbname);
...
$stmt = $conn->prepare('SELECT ...');
$stmt->bind_param(...);
$stmt->execute();
$stmt->bind_result(...);
while($stmt->fetch())
{
// do something here
}
$stmt->close();
...
// do something more here that has absolutely nothing to do with $stmt
這很好用.我得到了預期的結果,沒有錯誤或任何不應該發生的事情.
This works perfectly fine. I get the results I expected, there are no errors or anything that is not supposed to happen.
但是如果我將斷點(Xdebug 2.2.5/2.2.6/2.2.8/2.3.2 和 PHP 5.5.3/5.5.15/5.6.0/5.6.6/5.6.10)設置為一行之后 $stmt->close();
,我收到很多警告,比如
But if I set a break point (Xdebug 2.2.5 / 2.2.6 / 2.2.8 / 2.3.2 and PHP 5.5.3 / 5.5.15 / 5.6.0 / 5.6.6 / 5.6.10) to a line after $stmt->close();
, I get many warnings like
尚未允許訪問屬性
或
無法獲取 mysqli_stmt
Couldn't fetch mysqli_stmt
我以為我錯過了關閉另一個 mysqli 語句,但我得到了所有結果.我的代碼似乎沒有問題...
I thought I missed to close another mysqli statement, but I get all results. There seems to be just no problem in my code...
有沒有辦法擺脫這種錯誤警告?
Is there a way to get rid of this wrong warnings?
更新:這個問題在 PHP 7.0.1/Xdebug 2.4.0 RC3 中仍然存在.
Update: This problem still exist in PHP 7.0.1 / Xdebug 2.4.0 RC3.
推薦答案
有一些類似的問題報告
http://bugs.xdebug.org/view.php?id=900
https://bugs.php.net/bug.php?id=60778
擺脫此消息的一種方法是添加
One way to get rid of this messages is to add
unset($stmt);
在關閉語句之后和斷點之前.如果這沒有幫助,您還應該添加
after closing the statement and before the breakpoint. If this does not help, you should also add
unset($connection);
在@Martin 在評論中提到關閉連接之后.
after closing the connection as mentioned by @Martin in the comments.
這本身并不能解決問題,而是讓您繼續工作,直到這可能會在一段時間內得到解決.
This does not solve the problem itself, but let you go on with your work until this may be fixed some time.
編輯:現在還有一個報告的問題一個> :)
編輯:據報道,這似乎是 MySQLi 驅動程序中的一個錯誤 此處.
EDIT: This seems to be a bug in the MySQLi driver as reported here.
EDIT:如果您使用 PDO,看起來這個錯誤不會出現.所以這可能是切換到 PDO 的另一個原因.
EDIT: Looks like this bug does not appear if you use PDO. So this is maybe an other reason to switch to PDO.
這篇關于mysqli + xdebug 斷點后關閉語句導致很多警告的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!