流明发生错误:ConnectionFactory.php第226行中的InvalidArgumentException:不支持的驱动程序[mongodb]

时间:2018-10-30 09:24:59

标签: php mongodb laravel lumen

我正在使用lumen(laravel的微型框架)

1)我的php版本是7.0

2)我的系统是Windows 64位

3)使用xampp服务器

4)我已经在php / ext文件夹中添加了php_mongodb.dll

5)在php.ini文件中将扩展名添加为extension=php_mongodb.dll

6)重新启动apache正常

7)在管腔中添加如下包装

composer require illuminate/container ^5.2
composer require illuminate/support ^5.2
composer require jenssegers/mongodb ^3.2

8)如下所示在bootstrap / app.php文件中注册mongodb

$app->register('Jenssegers\Mongodb\MongodbServiceProvider');

9)在config文件夹中没有database.php文件。我已经为mysql和mongodb创建了数据凭证,因为我必须同时使用以下两者

<?php

return  [
    'default' => 'mysql',

    'connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'hostname'),
            'database'  => env('DB_DATABASE', 'databasename'),
            'username'  => env('DB_USERNAME', 'username'),
            'password'  => env('DB_PASSWORD', 'password'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

        'mongodb' => array(
            'driver'   => 'mongodb',
            'host'     => env('MONGODB_HOST', 'localhost'),
            'port'     => env('MONGODB_PORT', 27017),
            'username' => env('MONGODB_USERNAME', ''),
            'password' => env('MONGODB_PASSWORD', ''),
            'database' => env('MONGODB_DATABASE', 'databasename'),
            'options' => array(
                'db' => env('MONGODB_AUTHDATABASE', '') //Sets the auth DB
            )
        ),

    ],
];

10)在环境文件中也添加上述凭证

12)如下创建模型,

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\Model as MongoModel;

class MongoExample extends MongoModel
{
    protected $connection = 'mongodb';
    protected $collection = 'collectioname';
    public $timestamps    = false;
    protected $table = 'category_master'; 
    protected $fillable = ['id', 'category_name', 'status', 'created_at'];
    public static function listData()
    {
         $model = self::get();
        echo"<pre>";print_r($model);die;

    }
}

它给我以下错误,

InvalidArgumentException in ConnectionFactory.php line 226:
Unsupported driver [mongodb]

请告诉我我是否想念任何东西。

我将感谢您的回答,这将对我有所帮助。

0 个答案:

没有答案