工具:phpstudy.
增加数据:
<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function hello()
{
$user['title']="bbbb";
$user['text']=[
'email'=>"2306613258@qq.com",
'nickname'=>"新年",
];
$res=Db::name('user')->json(['text'])->save($user);
halt($res);
}
}
查询:
<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function hello()
{
$user['title']="bbbb";
$user['text']=[
'email'=>"2306613258@qq.com",
'nickname'=>"新年",
];
$res=Db::name('user')->json(['text'])->find(22);//查找id=22的数据
halt($res);
}
}
更新:
<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function hello()
{
$user['title']="bbbb";
$user['text']=[
'email'=>"2306611654@qq.com",
'nickname'=>"新年好呀,cyg",
];
$res=Db::name('user')->json(['text'])->where('id',22)->update($user);//查找id=22的数据
halt($res);
}
}
删除:
<?php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController
{
public function hello()
{
$user['title']="bbbb";
$user['text']=[
'email'=>"2306611654@qq.com",
'nickname'=>"新年好呀,cyg",
];
$res=Db::name('user')->json(['text'])->where('id',22)->delete();//查找id=22的数据
halt($res);
}
}