2013-09-27 27 views
0

我有一個在它下面的代碼一點點的PHP腳本:爲什麼我會在這裏調用未定義的函數findOne()?

$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 Fatal error: Call to undefined function findOne() in ...

現在,我已經下載並複製到ext目錄php_mongo.dll文件。此外,我已經添加了此行的php.ini

extension=php_mongo.dll 

,我已經重新啓動以來,服務器多次。

這真的感覺我這樣做findOne方法不可用,因爲php_mongo擴展未加載。但另一方面,創建MongoClient時不會拋出,也不會在抓取數據庫和集合時拋出。

這是怎麼回事?

+2

Myabe這裏是一個錯字,但'$ customers.findOne(..)'不應該是'$ customers-> findOne(..)'?這是PHP畢竟 –

+0

@DamienPirsy,補充說,作爲答案我的朋友!哇,我有點尷尬。我猜想,這發生在我們身上。 :D –

+0

是的,尤其是使用不同的語言,以及不同的屬性/方法訪問語法 –

回答

1

按我的意見,你可能誤用另一種語言的方法訪問語法:

$c = $customers.findOne(array('email' => $email)); 

是唉PHP所以你需要的對象操作符不是圓點:

$c = $customers->findOne(array('email' => $email)); 
1

我認爲點是mistake.try

$c = $customers->findOne(array('email' => $email)); 
相關問題