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 ...
随机推荐
- 如何在CentOS 7中安装最新Git(源码安装)
如何在CentOS 7中安装最新Git 2017年05月20日 11:49:53 阅读数:1624 Git是在今天的软件开发行业一个非常有用的版本控制工具.我一直使用Git.于是为Linux公社的读者 ...
- k8s pv 的三种挂载模式
ReadWriteOnce:可读可写,只能被一个Node节点挂载 ReadWriteMany:可读可写,可以被多个Node节点挂载 ReadOnlyMany:只读,能被多个Node节点挂载
- js树形结构-----(BST)二叉树增删查
function BinarySearchTree(){ var cnodes = function(key){ this.key = key; this.left = null; this.righ ...
- ICSharpCode.TextEditor使用及扩展
SharpDevelop (#develop)有很多“副产品”,其中最出名的应算SharpZipLib (#ziplib),纯C#的ZIP类库,而在SharpDevelop (#develop)中,“ ...
- jquery tooltip插件
qtip2:http://qtip2.com/ bower install qtip2 // lowercase! 引入一个css和插件即可. <script type="text/j ...
- (已解决)iOS真机运行 Xcode报错(libpng error: CgBI: unhandled critical chunk)
Cocos2d-x加载图片资源出现libpng error: CgBI: unhandled critical chunk Xcode7.3 设置Remove Text Metadata From P ...
- 「美团外卖APP签约快捷支付」流程体验
§1 添加银行卡 新用户在美团外卖APP订餐支付时,首先要绑定银行卡.如下是“添加银行卡”页,输入卡号后,系统自动调用卡bin库校验卡号的有效性,如果有效会显示发卡行和卡类型(借记卡/贷记卡). 这 ...
- 自定义Http请求头并且获取
在一些开发需求中.我们需要把一些信息放到Http请求头中.比如我需要把签名信息 signature 放到Http请求头 所以就需要自定义请求头 signature ,用webClient发起请求 我这 ...
- MySQL主从同步问题
1,The replication receiver thread cannot start because the master has GTID_MODE = OFF and this serve ...
- 462. 最少移动次数使数组元素相等 II
给定一个非空整数数组,找到使所有数组元素相等所需的最小移动数,其中每次移动可将选定的一个元素加1或减1. 您可以假设数组的长度最多为10000. 例如: 输入: [1,2,3] 输出: 2 说明: 只 ...