Chen Li Yong
Chen Li Yong

Reputation: 6097

Error on variable $mysqli->result which I don't access at all yet

I got this error:

Catchable fatal error: Object of class mysqli_result could not be converted to string in J:\xampp\htdocs\components\bo_testedit.php on line 50

And this is on bo_testedit.php line 50:

ExecSQL (__FILE__, $mysqli, "DELETE FROM question_assign WHERE id_question = {$id}");

And this is on functions_db.php:

function ExecSQL ($scriptparent, $mysqli, $query) {
    $mysqli->query ($query);
    if ($mysqli->error != "") { DBErrorLogger ($scriptparent, $mysqli->error, $query); return $mysqli->error; }
    return true;
}

And this is also on 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);
}

From what I've learned from googling, this error occurs because I want to store object $mysqli->result into a string type variable. One thing that bothers me here, I didn't access $mysqli->result in all these codes. Why it returns such error message? I do access it in another lines on bo_testedit.php, but they're seems fine (returning correct result). Is it possible that the line number from this error was incorrect (i.e refer to another line)?

EDIT: Sorry for the long reply. The problem persist of several days despite of anything I did, but then the problem suddenly disappear despite I didn't do anything to it. I still don't know where the problem is, but I surely do hope it will never coming back again. Thank you and sorry.

Upvotes: 0

Views: 63

Answers (1)

meda
meda

Reputation: 45490

$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();

Upvotes: 1

Related Questions