查询构造器curd

Original 2019-05-03 13:50:07 405
abstract:<?phpnamespace app\index\controller;use think\Db;use PDO;class Index{    //查询    public function index()    {    $res = Db::table('class')->field

<?php

namespace app\index\controller;

use think\Db;

use PDO;


class Index

{

    //查询

    public function index()

    {

    $res = Db::table('class')->field('r_id,r_name,r_fen')->where('p_id','=',2)->order('r_fen','desc')->limit(3)->select();

    // ->where('r_fen','<',90)

    var_dump($res);

    }

    //添加

    public function insert()

    {

    $data = [

    ['r_name'=>'aaaa',

    'r_city'=>'1111a',

    'r_fen'=>'78',

    'p_id'=>2],

    ['r_name'=>'aaaa',

    'r_city'=>'1111a',

    'r_fen'=>'78',

    'p_id'=>2],

    ['r_name'=>'aaaa',

    'r_city'=>'1111a',

    'r_fen'=>'78',

    'p_id'=>2]

    ];

    dump($data);


    $res = Db::table('class')->data($data)->insertAll();

    // $id = Db::getLastInsID();

    return "添加".$res;


    }

    //删除

    public function dle()

    {

    $id = 14;

    Db::table('class')->delete($id);

    }

    //修改

    public function upl()

    {

    Db::table('class')->where('r_id',1)->data(['r_name'=>'杨俊杰','r_fen'=>100])->update();

    }

}


Correcting teacher:西门大官人Correction time:2019-05-05 10:32:32
Teacher's summary:insert()和insertAll()方法的区别是什么?

Release Notes

Popular Entries