Search code examples
mongodblithium

PHP Fatal error: Class 'MongoDate' not found


I use lithium console (lithium/console/li3) to run some command and I get this error:

PHP Fatal error: Class 'MongoDate' not found

My system details:

  • mongodb server: 2.6.1
  • php mongodb client: 1.5.2
  • apache 2.4.7
  • php 5.5.9-1ubuntu4

$Requests = Requests::find('all', array('conditions'=>array( 'expired'=>array('<'=>new \MongoDate(time())), 'processed'=>0 )));

I don't have this error while running this code in older version system

  • PHP Version 5.3.10-1ubuntu3.11
  • Apache/2.2.22 (Ubuntu) Server
  • mongodb client: 1.4.5
  • mongodb server: 2.4.10

Thank you.

One more thing: I try to create just a simple script

$date = new MongoDate();

it runs without problem via webserver (browser) but if I use php command to run this file, I get the same error: Class 'MongoDate' not found So I believe that it's php command problem.


Solution

  • Make sure your mongodb extension is loaded.

    var_dump(extension_loaded('mongodb'));
    

    If not, you must load it in php.ini.