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

請問一下tporm模型數(shù)據(jù)庫連接怎么動態(tài)傳入配置

晚安。

問題描述

原文地址 http://www.wtbis.cn/q/9505
根據(jù)這個(gè)里面的實(shí)現(xiàn)還是要先在thinkorm.php 里面先定義好數(shù)據(jù)庫連接信息.這個(gè)文件不配置數(shù)據(jù)庫的信息
我這邊是數(shù)據(jù)庫配置信息都是存在數(shù)據(jù)庫
然后在控制器調(diào)用的時(shí)候傳入數(shù)據(jù)庫連接信息數(shù)組傳入。
根據(jù)這個(gè)傳入的數(shù)據(jù)庫配置信息來執(zhí)行查詢操作

程序代碼

模型
<?php

namespace app\api\model;

use think\Model;
use think\facade\Db;

/**
 * 用戶
 */
class UserModel extends Model
{
    // 表名
    protected $table = 'base_user';
    protected $connection;

    public function __construct($connection)
    {
        $this->connection = $connection;
        parent::construct($connection);
    }

}
控制器調(diào)用

$dd = [
            // 數(shù)據(jù)庫類型
            'type'            => 'mysql',
            // 服務(wù)器地址
            'hostname'        => '127.0.0.1',
            // 數(shù)據(jù)庫名
            'database'        => 'ceshi',
            // 數(shù)據(jù)庫用戶名
            'username'        => 'root',
            // 數(shù)據(jù)庫密碼
            'password'        => 'root',
            // 數(shù)據(jù)庫連接端口
            'hostport'        => '3306',
            // 數(shù)據(jù)庫連接參數(shù)
            'params'          => [
                // 連接超時(shí)3秒
                \PDO::ATTR_TIMEOUT => 3,
            ],
            // 數(shù)據(jù)庫編碼默認(rèn)采用utf8
            'charset'         => 'utf8mb4',
            // 數(shù)據(jù)庫表前綴
            'prefix'          => '',
            // 斷線重連
            'break_reconnect' => true,
            // 關(guān)閉SQL監(jiān)聽日志
            'trigger_sql' => true,
            // 自定義分頁類
            'bootstrap'       => '',
        ];
        $model = new UserModel($dd);
        $res = $model->select();

這樣測試不可以

操作系統(tǒng)及workerman/webman等框架組件具體版本

最新

856 0 0
0個(gè)回答

年代過于久遠(yuǎn),無法發(fā)表回答
??