laravel 数据库 - 增删查改
//查询
public function select(){ /**
数据表
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`sex` varchar(255) DEFAULT '1',
`create_at` int(11) DEFAULT '0',
`score` int(3) DEFAULT '0' COMMENT '分数',
`class_id` int(11) DEFAULT NULL COMMENT '班级id',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
CREATE TABLE `student_class` (
`class_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`is_show` int(11) DEFAULT NULL,
PRIMARY KEY (`class_id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
*/ $students = DB::table('student')->select('name as user_name')->get();
$user = DB::table('student')->where('name','Try')->first(); $name = DB::table('student')->where(['name'=>'Try'])->pluck('name'); $lists = DB::table('student')->lists('name'); $users = DB::table('Student')->where('age','>',22)->orWhere('sex','=',0)->get(); $users = DB::table('Student')->whereBetween('score',array(84,100))->get(); $users = DB::table('Student')->whereIn('score',array(85,95))->get();
$users = DB::table('Student')->whereNull('score')->get();
$users = DB::table('Student')->orderBy('score','desc')->having('score', '>', 84)->get(); $users = DB::table('Student')->join('Student_class','Student_class.class_id','=','Student.class_id')->get(); $users = DB::table('Student')->count();
$score = DB::table('Student')->max('score');
$score = DB::table('Student')->where('id',1)->sum('score','+','age'); //插入操作-批量插入
/*$id = DB::table('Student')->insert(
array(
array('name'=>'xiaohua','age'=>8,'sex'=>0,'score'=>33),
array('name'=>'xiaocao','age'=>9 ,'sex'=>0,'score'=>82)
)
);*/ $id = DB::table('Student')->where('id',5)->update(array('sex'=>1)); $id = DB::table('Student')->where('name','xiaocao')->delete();
$first = DB::table('Student')->whereNull('class_id');
$users = DB::table('Student')->whereNull('score')->union($first)->get(); $lock = DB::table('Student')->where('score', '>',
85)->sharedLock()->get();
$lock_update = DB::table('Student')->where('score', '>', 95)->lockForUpdate()->get(); dd($lock_update); }
laravel 数据库 - 增删查改的更多相关文章
- django models进行数据库增删查改
在cmd 上运行 python manage.py shell 引入models的定义 from app.models import myclass ##先打这一行 ------这些是 ...
- go iris xorm包使用(sqlite3数据库增删查改)
官网https://studyiris.com/example/orm/xorm.html例子,稍做修改 1.我是win64,但没有遇到mingw问题,应该是之前安装过gcc环境,参考:测试一下rob ...
- Django学习笔记009-django models进行数据库增删查改
引入models的定义 from app.models import myclass class myclass(): aa = models. CharField (max_length=No ...
- 【总结】C# Access 数据库 增删查改 的简单步骤
引用集: using System.Data.OleDb; static string exePath = System.Environment.CurrentDirectory;//本程序所 ...
- YII数据库增删查改操作
初学YII, 整理了一些YII数据库的相关操作, 共同学习,共同进步. 一.查询数据集合 //1.该方法是根据一个条件查询一个集合 $admin=Admin::model()->findAll ...
- SQL Server跨数据库 增删查改
比如你在库A ,想查询库B的表.可以用 数据库名.架构名.表名的方式查询 select * from 数据库B.dbo.表1 也可以在存储过程中这样使用. 需要注意的是,如果使用这样的查询方式,你必须 ...
- flask框架中,利用数据库增删查改
# 配置数据库app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:mysql@127.0.0.1:3306/booktest" ...
- Django框架model实现数据库增删查改
1.创建Django工程 https://www.cnblogs.com/CK85/p/10159159.html 2.在model.py中配置生成表格的类对象. from django.db imp ...
- MongoDB数据库(二):增删查改
MongoDB数据库的增删查改 1.插入数据 语法: db.集合名称.insert(document) db.table_name.insert({name:'gj',gender:1}) db.ta ...
随机推荐
- [py]字符串转换为列表
字符串转换为列表 "[1,2,3]" ==> [1,2,3]
- GlusterFS 配置及使用
GlusterFS集群创建 一.简介 GlusterFS概述 Glusterfs是一个开源的分布式文件系统,是Scale存储的核心,能够处理千数量级的客户端.在传统的解决 方案中Glusterfs能够 ...
- pip3 install pymysql
后续设置参考 “selenium python3” https://www.cnblogs.com/jpr-ok/p/10108231.html
- 《全栈性能Jmeter》-3JMeter体系结构
- mac 进程和线程工具
进程 查看端口进程 lsof lsof -i tcp:<port> 示例 $ lsof -i tcp:8082 COMMAND PID USER FD TYPE DEVICE SIZE/O ...
- ROSETTA使用技巧随笔--relax使用
Purpose: 主要说目的,relax的作用就是对一个给定的蛋白进行构象搜索,寻找与WT相似并能量低于WT的结构,既包含packer又包含minimizer.主要的应用在对一个结构构象进行取样,获得 ...
- iOS 开发笔记-报错处理
1.xcode7报错:does not contain bitcode 解决方法:Build Settings 搜索 bitcode 将Enable Bitcode更改为NO即可 2.Code Si ...
- MyBatis基础入门《十四》ResultMap子元素(association )
MyBatis基础入门<十四>ResultMap子元素(association ) 1. id: >> 一般对应数据库中改行的主键ID,设置此项可以提高Mybatis的性能 2 ...
- 从0开始搭建vue+webpack脚手架(二)
接着从0开始搭建vue+webpack脚手架(一) 三.配置webpack-dev-server 1. webpack-dev-server自带一个node的服务器, 项目在服务端运行的同时可以实现热 ...
- 在caffe-ssd安装编译环境运行make all时候报错:Makefile:572: recipe for target '.build_release/src/caffe/util/hdf5.o' failed make: *** [.build_release/src/caffe/util/hdf5.o] Error 1
解决办法: 修改:Makefile.config INCLUDE_DIRS /usr/include/hdf5/serial/ 修改:Makefile LIBRARIES hdf5_hl and hd ...