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 ...
随机推荐
- Spark:java.net.BindException: Address already in use: Service 'SparkUI' failed after 16 retries!
Spark多任务提交运行时候报错. java.net.BindException: Address already retries! at sun.nio.ch.Net.bind0(Native Me ...
- Spark DataFrame列的合并与拆分
版本说明:Spark-2.3.0 使用Spark SQL在对数据进行处理的过程中,可能会遇到对一列数据拆分为多列,或者把多列数据合并为一列.这里记录一下目前想到的对DataFrame列数据进行合并和拆 ...
- GRU门控制循环单元【转载】
转自:https://www.infoq.cn/article/sliced-recurrent-neural-networks 1.门控循环单元 GRU GRU 由 reset gate r 和 u ...
- 2019.03.30 图解HTTP
文章来源<图解HTTP> 第一章 了解Web及网络基础 你有想过当你在浏览器(web browser)的地址栏上输入URL时,Web页面是如何实现的吗? 嗯,好像也没想过 web使用一种名 ...
- Python 初始函数
python之路——初识函数 阅读目录 为什么要用函数 函数的定义与调用 函数的返回值 函数的参数 本章小结 为什么要用函数 我们就想啊,要是我们能像使用len一样使用我们这一大段“计算长度”的代 ...
- leetcode 108
二分法建立二叉树,每次把左半部分作为左子树右半部分作为右子树,递归建立BST. #include<bits/stdc++.h> using namespace std; /** * Def ...
- android 注入so
https://www.52pojie.cn/thread-564459-1-1.html
- ubuntu16.4菜单栏不见,终端不见解决方法
1.ctrl+alt+f1进入命令行 2. sudo apt-get install gnome-terminal 3.sudo apt-get install unity 4.setsid unit ...
- 使用vscode编译sass
如果你想通过命令行来编译的话 可以按照 https://www.sass.hk/ 前往这里按步骤安装,但是在安装淘宝镜像的时候会有问题,安装不成功,于是我就使用vscode来编译sass 第一步,再v ...
- 海量交通大数据应用平台MTDAP_nchang的经验记录
WRONGTYPE Operation against a key holding the wrong kind of value 根本的就是redis同一个key的value值前后类型不一致,比如最 ...