user1757768
user1757768

Reputation:

How to check if MongoDB error?

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

var_dump($mongodb->lastError());

gives me a blank page.

Upvotes: 1

Views: 4113

Answers (1)

W Kristianto
W Kristianto

Reputation: 9313

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

Upvotes: 1

Related Questions