laravel执行原生SQL语句进行增删改查


关于数据表的创建和对应的model请见上一篇博客。

1.添加数据

DB::insert('insert into student (name,sex,age) value (?,?,?)', ['jack', 2, 19]);

 

2.查询数据

DB::select('select * from student');

 

3.修改数据

DB::update('update student set name = ? where id = ?', ['emma',2]);

 

4.删除数据

DB::delete('delete from student where id > ?', [1]);

 

更多请查看laravel手册:https://learnku.com/docs/laravel/8.x/database/9400#420e1e

 

【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://www.cnblogs.com/facetwitter/p/15781205.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM