php - 变量 $mysqli->result 出现错误,我还没有访问该变量

标签 php mysql mysqli

我收到此错误:

可捕获的 fatal error :第 50 行的 J:\xampp\htdocs\components\bo_testedit.php 中的 mysqli_result 类对象无法转换为字符串

>

这是在 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 上的另一行中访问了它,但它们似乎很好(返回正确的结果)。此错误的行号是否可能不正确(即引用另一行)?

编辑:抱歉回复太长。尽管我做了任何事情,问题仍然持续了几天,但随后,尽管我没有采取任何措施,问题却突然消失了。我仍然不知道问题出在哪里,但我确实希望它永远不会再出现。谢谢你,也很抱歉。

最佳答案

$query = "DELETE FROM question_assign WHERE id_question = ?";
if ($stmt = $mysqli->prepare($query)) {   
    $stmt->bind_param('i', $id);
    /* execute query */
    $stmt->execute();    
    /*Count the rows*/
    if($stmt->num_rows > 0){
       echo 'It worked !';
    }else{
      var_dump($mysqli->error);
      die();
    }   
    /* close statement */
    $stmt->close();
}   
/* close connection */
$mysqli->close();

关于php - 变量 $mysqli->result 出现错误,我还没有访问该变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585397/

相关文章:

php - 加入 - 语法错误

mysql - and 与 AND 之间有区别吗

mysql - 两列索引为一列,或一列索引

javascript - jquery get 语法与 php 和 mysql 进行输入验证

php - Echo函数跳出Div

php - 检查数组和数组对象的 is_array

mysql - 在 MySQL 中添加 last_update 字段是一个好习惯吗?

php - MySQLi 选择 PHP 变量

php - mysqli准备的问题变量数量不匹配

php - 在 fetch_assoc 之前,mysql 中有多少行?