thinkphp 链接数据库

<?php

namespace  appindexcontroller;
use thinkDb;

class Demo4
{
    public function conn1()
    {
        return Db::table('daohang')->where('id',1)->value('title');
    }

    public function conn2()
    {
        return Db::connect([
            'type'=>'mysql',
            'hostname'=>'127.0.0.1',
            'database'=>'ceshi',
            'username'=>'root',
            'password'=>'root',
        ])
            ->table('admin')
            ->where('id',1)
            ->value('username');
    }

}

  php知识网

原文地址:https://www.cnblogs.com/furuihua/p/13645943.html