1

How can I check to see if there was an error with MongoDB?

var_dump($mongodb->lastError());

gives me a blank page.

4
  • 2
    Use "getLastError", not just "lastError". Commented Oct 18, 2012 at 22:47
  • Are you using echo or var_dump? Can we see your full code? Commented Oct 18, 2012 at 22:49
  • var_dump($mongodb->lastError()) Commented Oct 18, 2012 at 22:51
  • If you want to learn about the blank page you might find this helpful: stackoverflow.com/questions/12769982/… Commented Oct 18, 2012 at 22:58

1 Answer 1

1

Mongo::lastError — Check if there was an error on the most recent db operation performed

Deprecated

// NOT WORK!!
$mongo = new Mongo();
var_dump($mongo->lastError());

You only see a blank page because you have error reporting turned off in your PHP configuration.


MongoDB::lastError — Check if there was an error on the most recent db operation performed

You need MongoDB class

// WORK!!
$mongo = new Mongo();
$db    = $mongo->database;
var_dump($db->lastError());
Sign up to request clarification or add additional context in comments.

4 Comments

ini_set('display_errors', 1); i have message Function Mongo::lastError() is deprecated
$mongo = new Mongo(); $db = $mongo->database; var_dump($mongo->lastError());
$mongo->lastError() --> $db->lastError()
Thank you :) it works array(4) { ["n"]=> int(0) ["connectionId"]=> int(4) ["err"]=> NULL ["ok"]=> float(1) }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.