赣南脐橙

keybr

佰草伐

导航

thinkphp 数据库操作

<?php

namespace app\index\controller;
use think\Db;
class Demo5
{
    public function find()
    {
        $res = Db::table('daohang')
           // ->field('id,title,url')
               ->field(['id as 编号'])
                ->find();
        dump($res);
    }
    public  function select()
    {
       $res =  Db::table('daohang')
            ->field('id,title,url')
            ->where([
                ['id','=',2],
                ['aid','=',1]
            ])
            ->select();
       foreach($res as $row){
           dump($row);
       }
    }
    public function insert()
    {
        $data=[
          'aid'=>'1',
            'title'=>'直线电机厂家',
            'url'=>'https://www.bzddrive.com'
        ];
       return Db::table('daohang')->insert($data);
       //INSERT INTO `daohang` (`aid` , `title` , `url`) VALUES (1 , '直线电机厂家' , 'https://www.bzddrive.com')
    }
    public function  insertAll()
    {
        $data =[
            ['aid'=>'1','title'=>'直线驱动电机','url'=>'https://www.bzddrive.com'],
            ['aid'=>'1','title'=>'dd马达','url'=>'https://www.bzddrive.com'],
            ['aid'=>'1','title'=>'环形直线电机','url'=>'https://www.bzddrive.com'],
        ];
        return Db::table('daohang')->insertAll($data);
    }
    public function update()
    {
        return Db::table('daohang')->where('id',16)->update(['title'=>'直线电机参数']);
    }
    public  function delete()
    {
        return Db::table("daohang")->where('id',16)->delete();
    }

}

  php知识网

posted on 2020-09-10 15:30  佰草伐  阅读(86)  评论(0编辑  收藏  举报

keybr

php基础知识

Wood Furniture