本文介绍了致命错误:使用mongodb php驱动程序1.1.2和PHP 7.0.2时找不到类'MongoDate'-Laravel 5.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MongoDB配置为与虚拟Ubuntu 14.04计算机上的Laravel 5.1 Homestead实例一起使用.我能够使用sudo pecl install mongodb成功安装支持PHP 7.0的最新版本的MongoDB(这对于7.0是正确的,不再 sudo pecl install mongo不再适用).

I am trying to configure MongoDB to work with my Laravel 5.1 Homestead instance on a virtual Ubuntu 14.04 machine. I was able to successfully install the latest version of MongoDB which supports PHP 7.0 using sudo pecl install mongodb (this is correct for 7.0, not sudo pecl install mongo anymore).

然后,我在Ubuntu计算机上的php.ini文件(全部三个)中添加了扩展名,每个文件位于:

I then added the extension in my php.ini files (all three) on my Ubuntu machine, each in:

  • /etc/php/7.0/cli/php.ini
  • /etc/php/7.0/fpm/php.ini
  • /etc/php/7.0/cgi/php.ini
  • /etc/php/7.0/cli/php.ini
  • /etc/php/7.0/fpm/php.ini
  • /etc/php/7.0/cgi/php.ini

这是我编写的扩展名,它与PHP 7.0正确使用:

This is the extension I wrote which is correct for use with PHP 7.0:

  • extension=mongodb.so(不再是mongo.so)
  • extension=mongodb.so (not mongo.so anymore)

当我在浏览器中运行phpinfo()时,它表明MongoDB已使用我的PHP 7.0进行了正确配置.

When I run phpinfo() in my browser, it states that MongoDB is properly configured with my PHP 7.0.

如果MongoDB配置正确,我将如何获得:

If MongoDB is properly configured, how come I keep getting:

Fatal error: Class 'MongoDate' not found

当我尝试使用php artisan migrate:refresh --seed运行迁移和种子时?

when I try to run my migrations and seeds with php artisan migrate:refresh --seed?

我已经尝试过:

  • 使用vagrant reloadvagrant reload --provision
  • 重新引导Ubuntu计算机
  • 使用sudo service nginx restartsudo service php7.0-fpm restart
  • 重新启动PHP和Nginx
  • rebooting the Ubuntu machine with vagrant reload and vagrant reload --provision
  • Restarting PHP and Nginx with sudo service nginx restart and sudo service php7.0-fpm restart

都没有用.

推荐答案

如前所述,您正在使用适用于PHP 7的新Mongo扩展.

As you mentioned you're using the new Mongo extension for PHP 7.

类名已从旧版本更改,即

The class names have changed from the older version, i.e.

MongoClient现在是MongoDB\Driver\Manager

MongoDate现在为MongoDB\BSON\UTCDateTime

我不确定所有内容都向后兼容,但这应该可以让您入门!

I'm not sure how backwards compatible everything is, but this should get you started!

这篇关于致命错误:使用mongodb php驱动程序1.1.2和PHP 7.0.2时找不到类'MongoDate'-Laravel 5.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:11