企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 基本使用 配置了数据库连接信息后,我们就可以直接使用数据库运行原生SQL操作了,支持`query`(查询操作)和`execute`(写入操作)方法,并且支持参数绑定。 ``` Db::query('select * from think_user where id=?',[8]); Db::execute('insert into think_user (id, name) values (?, ?)',[8,'thinkphp']); ``` 也支持命名占位符绑定,例如: ``` Db::query('select * from think_user where id=:id',['id'=>8]); Db::execute('insert into think_user (id, name) values (:id, :name)',['id'=>8,'name'=>'thinkphp']); ``` 可以使用多个数据库连接,使用 ``` Db::connect($config)->query('select * from think_user where id=:id',['id'=>8]); ``` $config是一个单独的数据库配置,支持数组和字符串,也可以是一个数据库连接的配置参数名。