PHP Fatal error: Class 'MongoDate' not found

泪湿孤枕 提交于 2019-12-10 17:43:54

问题


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.


回答1:


Make sure your mongodb extension is loaded.

var_dump(extension_loaded('mongodb'));

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




回答2:


For people that have come here using PHP7, the classs has been renamed:

MongoDate is now MongoDB\BSON\UTCDateTime

Also I've found that this now wants miliseconds instead of seconds, so make sure you multiple your input by 1000, for example:

$date = new \MongoDB\BSON\UTCDateTime(strtotime('yesterday') * 1000);


来源:https://stackoverflow.com/questions/23866598/php-fatal-error-class-mongodate-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!