//查询
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 数据库 - 增删查改的更多相关文章

  1. django models进行数据库增删查改

    在cmd 上运行 python manage.py shell   引入models的定义 from app.models import  myclass   ##先打这一行    ------这些是 ...

  2. go iris xorm包使用(sqlite3数据库增删查改)

    官网https://studyiris.com/example/orm/xorm.html例子,稍做修改 1.我是win64,但没有遇到mingw问题,应该是之前安装过gcc环境,参考:测试一下rob ...

  3. Django学习笔记009-django models进行数据库增删查改

    引入models的定义 from app.models import  myclass class  myclass(): aa =  models. CharField (max_length=No ...

  4. 【总结】C# Access 数据库 增删查改 的简单步骤

        引用集: using System.Data.OleDb; static string exePath = System.Environment.CurrentDirectory;//本程序所 ...

  5. YII数据库增删查改操作

    初学YII, 整理了一些YII数据库的相关操作,  共同学习,共同进步. 一.查询数据集合 //1.该方法是根据一个条件查询一个集合 $admin=Admin::model()->findAll ...

  6. SQL Server跨数据库 增删查改

    比如你在库A ,想查询库B的表.可以用 数据库名.架构名.表名的方式查询 select * from 数据库B.dbo.表1 也可以在存储过程中这样使用. 需要注意的是,如果使用这样的查询方式,你必须 ...

  7. flask框架中,利用数据库增删查改

    # 配置数据库app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:mysql@127.0.0.1:3306/booktest" ...

  8. Django框架model实现数据库增删查改

    1.创建Django工程 https://www.cnblogs.com/CK85/p/10159159.html 2.在model.py中配置生成表格的类对象. from django.db imp ...

  9. MongoDB数据库(二):增删查改

    MongoDB数据库的增删查改 1.插入数据 语法: db.集合名称.insert(document) db.table_name.insert({name:'gj',gender:1}) db.ta ...

随机推荐

  1. Hybrid设计--离线更新

    首先server端和前端做一个增量发布系统 ,1.就是把一个增量包发布到一个版本的Native上去,让他做更新.2.后台对这个增量包的到达率或者成功的更新做一个统计.这是比较复杂的. 离线更新的机制: ...

  2. iOSOpenDev安装使用

    下载:http://iosopendev.com/download/ 选择“iOSOpenDev 1.6-2 Installer” 出错解决方法 https://www.jianshu.com/p/2 ...

  3. Solaris 10主机名和IP地址步骤

    1.修改主机名: hostname newname vi /etc/hosts vi /etc/hostname.e1000g0 vi /etc/nodename init 6 #重启 --confi ...

  4. RNN的深入理解

    针对有着前后序列关系的数据,比如说随着时间变化的数据,显然使用rnn的效果会更好. 循环神经网络的简单结构如下图:简单表示是左边这幅图,展开来看就是右边对每个时刻的数据的处理.单层的RNN网络只有一个 ...

  5. MyBatis基础入门《十八》动态SQL(if-where)

    MyBatis基础入门<十八>动态SQL(if-where) 描述: 代码是在<MyBatis基础入门<十七>动态SQL>基础上进行改造的,不再贴所有代码,仅贴改动 ...

  6. Oracle 23的用户管理

    创建用户的语法格式 Create user <user_name> Identified by<password> Default tabespace<default t ...

  7. Mongo数据两表关联创建视图示例

    表tblCard: {"cNo":"11","oRDate":ISODate("2017-08-01T00:00:00.000+0 ...

  8. Python记录7:函数3,函数对象

    #函数对象指的是:函数的内存地址可以像变量值一样去使用,如何使用?def func(): print('from func')#1. 可以被引用# f=func# print(f)# f() #2. ...

  9. Python记录3:集合

    #一,集合类型###找出两个集合的交集并将结果打印出来# python_stu=['egon','alex','kevin','王大炮','李二丫']# linux_stu=['张铁蛋','刘铜蛋', ...

  10. ABC3

    Sql Server http://www.cnblogs.com/sunxi/p/4600152.html http://blog.csdn.net/dmz1981/article/details/ ...