[英]Why am I getting “Call to undefined function findOne()” here?
我有一個PHP腳本,其中包含以下代碼:
$m = new MongoClient(Settings::$db);
$db = $m->db;
// get the 'customers' collection
$customers = $db->customers;
// determine if this customer already exists
$c = $customers.findOne(array('email' => $email)); <--- throws
if (is_null($c)) {
$customers.insert(array(
'email' => $email,
'firstname' => $firstName,
'lastname' => $lastName
));
}
// get the 'payments' collection
$payments = $db->payments;
// add a record
$payments->insert(array(
'email' => $email,
'firstname' => $firstName,
'lastname' => $lastName,
'amount' => $price,
'token' => $token
));
但它正在拋出錯誤:
PHP致命錯誤:在...中調用未定義的函數findOne()
現在,我已經下載並復制到ext
目錄下的php_mongo.dll
文件。 此外,我已將此行添加到php.ini
:
extension=php_mongo.dll
我已經多次重啟服務器了。
我真的覺得這樣的findOne
方法不可用,因為沒有加載php_mongo
擴展。 但另一方面,它在創建MongoClient
時不會拋出,也不會在抓取數據庫和集合時拋出。
這里發生了什么?
我認為dot是錯誤的
$c = $customers->findOne(array('email' => $email));
根據我的評論,你可能錯誤地使用了另一種語言的方法訪問語法:
這個
$c = $customers.findOne(array('email' => $email));
是PHP,所以你需要對象操作符而不是點:
$c = $customers->findOne(array('email' => $email));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.