企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
数据库原生sql写法(返回值为影响行数) //执行数据库操作 $res = db()->execute($sql); 1.查询操作 Db::query('select * from user where id<=? and id>=?',[8,5]); //?为占位符,8和5为对应参数 Db::query('select * from user where id=:id',['id'=>8]); 例: $id = 1; $data = Db::query("select * from user where id =?",[$id]); 2.写入操作 Db::execute('insert into user (id, name) value (?, ?)',[2,'zhangsan']); Db::execute('insert into user (id,name) value (:id, :name)',['id'=>2,'name'=>'zhangsan']); 3.修改 Db::execute("update user set age='20' where id=9"); 4.删除 Db::execute("delete from user where id=20"); Db::execute("delete from user where id>?",[20]); Db::execute("delete from user where id=:id",['id'=>20]); //打印出执行的sql语句(打印出最后一条sql语句) echo Db::getLastSql();