2
我有一個PHP平臺,在這裏用戶寫入的mongodb查詢像圖片下面PHP MongoDB的異常(錯誤處理)
和下面的代碼打印結果作爲表
$m = new MongoClient();
$db = $m->Forensic;
$coll= $db->mobile_data;
if (isset($_POST['txt_area']) && !empty($_POST['txt_area'])) {
$d = ($_POST['txt_area']);
$p = json_decode($d);
$user_code = $coll->find($p);
當I型正確的代碼系統能夠輸出我所有的結果,但如果我寫錯誤的查詢,我會得到如下錯誤消息:
Warning: MongoCollection::find(): expects parameter 1 to be an array or object, null given in C:\xampp\htdocs\reports5.php on line 126
趕上這個錯誤我已經嘗試以下嘗試捕捉的代碼,但沒有運氣
try {
if (isset($_POST['txt_area']) && !empty($_POST['txt_area'])) {
$d = ($_POST['txt_area']);
$p = json_decode($d);
$user_code = $coll->find($p);
$NumberOfRow2 = $user_code->count();
$user_code->sort(array('Chat_group' => -1, 'Instant_Message' => 1));
}
}
catch (MongoCursorException $e) {
echo "error message: ".$e->getMessage()."\n";
echo "error code: ".$e->getCode()."\n";
}
catch (MongoException $e)
{
echo $e->getMessage();
}
catch(MongoResultException $e) {
echo $e->getMessage(), "\n";
$res = $e->getDocument();
var_dump($res);
}
這將是趕上上述錯誤
大!謝謝 – Sumon