我正在使用pecl驱动程序在PHP中使用MongoDB.我的更新工作得很好,但我想在我的函数中构建一些错误检查.
我尝试在一个非常简单的函数中使用lastError():
function system_db_update_object($query, $values, $database, $collection) {
$connection = new Mongo();
$collection = $connection->$database->$collection;
$connection->$database->resetError(); //Added for debugging
$collection->update(
$query,
array('$set' => $values));
//$errorArray = $connection->$database->lastError();
var_dump($connection->$database->lastError());exit; // Var dump and /Exit/
}
Run Code Online (Sandbox Code Playgroud)
但几乎不管我尝试更新(无论是否存在),我都得到了相同的基本结果:
array(4) {
["err"]=>
NULL
["updatedExisting"]=>
bool(true)
["n"]=>
float(1)
["ok"]=>
float(1)
}
Run Code Online (Sandbox Code Playgroud)
我如何知道更新是成功还是失败?