安装think-orm后 运行报错

weywey

问题描述

安装think-orm后使用Db查询时报错。

程序代码

<?php

namespace app\adminuser\service;

use think\facade\Db;

class RegionService
{
    /**
     * @desc:查询列表
     * @param $param
     * 2023/5/5 16:44
     */
    public static function getList($param){
        $filter = [];
        if (isset($param['name'])) {
            $filter['name'] = ['like', "%{$param['name']}%"];
        }
        if (isset($param['level'])) {
            $filter['level'] = ['IN', $param['level']];
        }
        $data = Db::table('region')
            ->where($filter)
            ->page($param['page'],$param['limit'])
            ->select();
        var_dump($data);
    }

}

thinkorm.php 代码如下 
<?php

return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            // 数据库类型
            'type' => 'mysql',
            // 服务器地址
            'hostname' => '127.0.0.1',
            // 数据库名
            'database' => 'map',
            // 数据库用户名
            'username' => 'map',
            // 数据库密码
            'password' => '123456',
            // 数据库连接端口
            'hostport' => '3306',
            // 数据库连接参数
            'params' => [
                // 连接超时3秒
                \PDO::ATTR_TIMEOUT => 3,
            ],
            // 数据库编码默认采用utf8
            'charset' => 'utf8',
            // 数据库表前缀
            'prefix' => '',
            // 断线重连
            'break_reconnect' => true,
            // 关闭SQL监听日志
            'trigger_sql' => false,
            // 自定义分页类
            'bootstrap' =>  ''
        ],
    ],
];


在这里打印 居然读不到配置信息。

报错信息

{
    "code": 500,
    "msg": "Undefined db config:mysql",
    "traces": "InvalidArgumentException: Undefined db config:mysql in /www/wwwroot/webman_map/webman/vendor/topthink/think-orm/src/DbManager.php:248\nStack trace:\n#0 /www/wwwroot/webman_map/webman/vendor/topthink/think-orm/src/DbManager.php(261): think\\DbManager->getConnectionConfig('mysql')\n#1 /www/wwwroot/webman_map/webman/vendor/topthink/think-orm/src/DbManager.php(233): think\\DbManager->createConnection('mysql')\n#2 /www/wwwroot/webman_map/webman/vendor/topthink/think-orm/src/DbManager.php(216): think\\DbManager->instance('mysql', false)\n#3 /www/wwwroot/webman_map/webman/vendor/topthink/think-orm/src/DbManager.php(374): think\\DbManager->connect()\n#4 [internal function]: think\\DbManager->__call('table', Array)\n#5 /www/wwwroot/webman_map/webman/vendor/topthink/think-container/src/Facade.php(96): call_user_func_array(Array, Array)\n#6 /www/wwwroot/webman_map/webman/app/adminuser/service/RegionService.php(25): think\\Facade::__callStatic('table', Array)\n#7 /www/wwwroot/webman_map/webman/app/adminuser/controller/Region.php(26): app\\adminuser\\service\\RegionService::getList(Array)\n#8 /www/wwwroot/webman_map/webman/vendor/workerman/webman-framework/src/App.php(319): app\\adminuser\\controller\\Region->index(Object(support\\Request))\n#9 /www/wwwroot/webman_map/webman/vendor/workerman/webman-framework/src/App.php(349): Webman\\App::Webman\\{closure}(Object(support\\Request))\n#10 /www/wwwroot/webman_map/webman/app/middleware/AccessControlTest.php(13): Webman\\App::Webman\\{closure}(Object(support\\Request))\n#11 /www/wwwroot/webman_map/webman/vendor/workerman/webman-framework/src/App.php(341): app\\middleware\\AccessControlTest->process(Object(support\\Request), Object(Closure))\n#12 /www/wwwroot/webman_map/webman/vendor/workerman/webman-framework/src/App.php(141): Webman\\App::Webman\\{closure}(Object(support\\Request))\n#13 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Connection/TcpConnection.php(646): Webman\\App->onMessage(Object(Workerman\\Connection\\TcpConnection), Object(support\\Request))\n#14 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Events/Select.php(311): Workerman\\Connection\\TcpConnection->baseRead(Resource id #173)\n#15 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Worker.php(1629): Workerman\\Events\\Select->loop()\n#16 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Worker.php(1423): Workerman\\Worker::forkOneWorkerForLinux(Object(Workerman\\Worker))\n#17 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Worker.php(1397): Workerman\\Worker::forkWorkersForLinux()\n#18 /www/wwwroot/webman_map/webman/vendor/workerman/workerman/Worker.php(560): Workerman\\Worker::forkWorkers()\n#19 /www/wwwroot/webman_map/webman/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\\Worker::runAll()\n#20 /www/wwwroot/webman_map/webman/start.php(4): support\\App::run()\n#21 {main}"
}
1187 1 0
1个回答

weywey

检查了配置文件 也配置了

  • damao 2023-05-05

    配置文件是config/thinkorm.php, 不是config/database.php

  • weywey 2023-05-05

    是配置的thinkorm

年代过于久远,无法发表回答
×
🔝