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

請(qǐng)問(wèn)一下tporm模型數(shù)據(jù)庫(kù)連接怎么動(dòng)態(tài)傳入配置

晚安。

問(wèn)題描述

原文地址 http://wtbis.cn/q/9505
根據(jù)這個(gè)里面的實(shí)現(xiàn)還是要先在thinkorm.php 里面先定義好數(shù)據(jù)庫(kù)連接信息.這個(gè)文件不配置數(shù)據(jù)庫(kù)的信息
我這邊是數(shù)據(jù)庫(kù)配置信息都是存在數(shù)據(jù)庫(kù)
然后在控制器調(diào)用的時(shí)候傳入數(shù)據(jù)庫(kù)連接信息數(shù)組傳入。
根據(jù)這個(gè)傳入的數(shù)據(jù)庫(kù)配置信息來(lái)執(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ù)庫(kù)類型
            'type'            => 'mysql',
            // 服務(wù)器地址
            'hostname'        => '127.0.0.1',
            // 數(shù)據(jù)庫(kù)名
            'database'        => 'ceshi',
            // 數(shù)據(jù)庫(kù)用戶名
            'username'        => 'root',
            // 數(shù)據(jù)庫(kù)密碼
            'password'        => 'root',
            // 數(shù)據(jù)庫(kù)連接端口
            'hostport'        => '3306',
            // 數(shù)據(jù)庫(kù)連接參數(shù)
            'params'          => [
                // 連接超時(shí)3秒
                \PDO::ATTR_TIMEOUT => 3,
            ],
            // 數(shù)據(jù)庫(kù)編碼默認(rèn)采用utf8
            'charset'         => 'utf8mb4',
            // 數(shù)據(jù)庫(kù)表前綴
            'prefix'          => '',
            // 斷線重連
            'break_reconnect' => true,
            // 關(guān)閉SQL監(jiān)聽(tīng)日志
            'trigger_sql' => true,
            // 自定義分頁(yè)類
            'bootstrap'       => '',
        ];
        $model = new UserModel($dd);
        $res = $model->select();

這樣測(cè)試不可以

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

最新

968 0 0
0個(gè)回答

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