//查询
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. 10.110.20.16上的MQTT server

    apollo 10.110.20.16    root    XnlzeNP2 /var/lib/apache-apollo-1.7.1 1  创建broker 进入 bin  创建 broker  ...

  2. 【LeetCode每天一题】Longest Palindromic Substring(最长回文字串)

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  3. [LeetCode] 696. Count Binary Substrings_Easy

    利用group, 将每个连着的0或者1计数并且append进入group里面, 然后再将group里面的两两比较, 得到min, 并且加入到ans即可.   T: O(n)   S: O(n)  比较 ...

  4. iOS库

    https://medium.com/app-coder-io/33-ios-open-source-libraries-that-will-dominate-2017-4762cf3ce449#.i ...

  5. Linux Performance 一文

    http://www.brendangregg.com/linuxperf.html Brendan D. Gregg 专注 Linux performance & tuning 许多年,其博 ...

  6. kettle杂记

    版本8.0,以下是我在使用kettle时候的一些小tips 1.“插入/更新”必须指定字段,“表输出”无需指定字段,但是源表的字段必须包含在目标表中,否则unknown colum! 2.连接数据库时 ...

  7. word之论文摘要

    字数在500个汉字左右

  8. ABC2

    OpenCV http://www.cnblogs.com/skyfsm/p/7263773.html http://www.cnblogs.com/skyfsm/p/7613314.html SQL ...

  9. Cocos Creator学习目录

    目录 安装和启动 文件结构 编辑器基础 基本概念 (场景树 节点 坐标 组件 ) Cocos Creator 脚本简介 Cocos Creator调试 节点 cc.Node 组件开发cc.Compon ...

  10. Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。

    解决办法如下: 1.在_Layout.cshtml布局body内,添加section,Scripts.Render和RenderSection标签示例代码如下: <body class=&quo ...