<?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知识网