国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

MongoDB

webman默認(rèn)使用 jenssegers/mongodb 作為mongodb組件,它是從laravel項(xiàng)目中抽離出來的,用法與laravel相同。

使用jenssegers/mongodb之前必須先給php-cli安裝mongodb擴(kuò)展。

使用命令php -m | grep mongodb查看php-cli是否裝了mongodb擴(kuò)展。注意:即使你在php-fpm安裝了mongodb擴(kuò)展,不代表你在php-cli可以使用它,因?yàn)?code>php-cli和php-fpm是不同的應(yīng)用程序,可能使用的是不同的php.ini配置。使用命令php --ini來查看你的php-cli使用的是哪個(gè)php.ini配置文件。

安裝

PHP>7.2時(shí)

composer require -W illuminate/database jenssegers/mongodb ^3.8.0

PHP=7.2時(shí)

composer require -W illuminate/database jenssegers/mongodb ^3.7.0

安裝后需要restart重啟(reload無效)

配置

config/database.php 里增加 mongodb connection, 類似如下:

return [

    'default' => 'mysql',

    'connections' => [

         ...這里省略了其它配置...

        'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => '127.0.0.1',
            'port'     =>  27017,
            'database' => 'test',
            'username' => null,
            'password' => null,
            'options' => [
                // here you can pass more settings to the Mongo Driver Manager
                // see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use

                'appname' => 'homestead'
            ],
        ],
    ],
];

示例

<?php
namespace app\controller;

use support\Request;
use support\Db;

class UserController
{
    public function db(Request $request)
    {
        Db::connection('mongodb')->collection('test')->insert([1,2,3]);
        return json(Db::connection('mongodb')->collection('test')->get());
    }
}

更多內(nèi)容請?jiān)L問

https://github.com/jenssegers/laravel-mongodb

編輯于2025-02-06 22:08:54 完善本頁 +發(fā)起討論
贊助商