我得到這個錯誤:
開捕致命錯誤:類mysqli_result的對象無法轉換爲字符串j:\ XAMPP \ htdocs中\部件\ bo_testedit.php上線50
這是上bo_testedit.php
線50:
ExecSQL (__FILE__, $mysqli, "DELETE FROM question_assign WHERE id_question = {$id}");
這是上functions_db.php
:
function ExecSQL ($scriptparent, $mysqli, $query) {
$mysqli->query ($query);
if ($mysqli->error != "") { DBErrorLogger ($scriptparent, $mysqli->error, $query); return $mysqli->error; }
return true;
}
,這也是對functions_db.php
:
function DBErrorLogger ($functionname, $error, $query = "") {
$logmessage = "<br>Functions_db.php:\nFunction <strong>{$functionname}</strong> raised error:<br>\n{$error}";
if ($query != "") $logmessage = $logmessage . "<br>\nwhile executing this query: \n<strong>{$query}</strong>";
Logger ($logmessage);
}
從我從谷歌上搜索得知,因爲我要的對象$mysqli->result
存儲到一個字符串類型變量出現此錯誤。在這裏困擾我的一件事是,我沒有在所有這些代碼中訪問$mysqli->result
。爲什麼它返回這樣的錯誤信息?我可以在bo_testedit.php
的另一行訪問它,但它們看起來很好(返回正確的結果)。這個錯誤的行號有可能是不正確的(即參考另一行)?
編輯:對不起,很長的答覆。儘管我做了任何事情,問題仍然存在好幾天,但隨後問題突然消失,儘管我沒有做任何事情。我仍然不知道問題出在哪裏,但我確實希望它永遠不會再回來。謝謝你,對不起。
'$ mysqli-> error'包含什麼?你可以給一個'var_dump();'? – Bono
好像你可以修復錯誤,並通過使用準備好的語句和參數替換而不是字符串替換來獲得更好的注入安全性。 – RobP
一個建議:不要檢查if($ mysqli-> error!=「」)'檢查返回值: '$ result = $ mysqli-> query($ query); if($ result === false) ' – RobP