sql:
model:
代码语言:javascript复制<?php
namespace appmodel;
use thinkModel;
class Aaa extends Model
{
}
controller:
代码语言:javascript复制<?php
namespace appindexcontroller;
use appBaseController;
use thinkfacadeDb;
use appmodelAaa;
class Index extends BaseController
{
public function hello()
{
$user=new Aaa();
$data=['name'=>"vvvv"];
$user->allowField(['name'])->save($data);//只能name插入数据
}
}
修改:
代码语言:javascript复制<?php
namespace appindexcontroller;
use appBaseController;
use thinkfacadeDb;
use appmodelAaa;
class Index extends BaseController
{
public function hello()
{
$user=Aaa::where('name',"vvvv")->find();//找到name为vvvv的字段
$user->name="liwen";//修改其name值
$user->save();
}
}
修改的第二种方式:
代码语言:javascript复制<?php
namespace appindexcontroller;
use appBaseController;
use thinkfacadeDb;
use appmodelAaa;
class Index extends BaseController
{
public function hello()
{
Aaa::update(['name'=>"fff",'id'=>3]);
}
}
删除:
代码语言:javascript复制<?php
namespace appindexcontroller;
use appBaseController;
use thinkfacadeDb;
use appmodelAaa;
class Index extends BaseController
{
public function hello()
{
$user=Aaa::find(2);
$user->delete();
}
}
查询:
代码语言:javascript复制<?php
namespace appindexcontroller;
use appBaseController;
use thinkfacadeDb;
use appmodelAaa;
class Index extends BaseController
{
public function hello()
{
$aaa=Aaa::select([3,4]);
halt($aaa);
}
}