批改状态:合格
老师批语:完成的不错。
TP多例模式的设置
1、config 文件夹下的config 多例配置
2、controller 文件放到新项目文件夹下,需调整原有的命名空间,如原命名空间为 app\controller 需要改为 app\新文件夹名\controller
<?php
namespace app\test1\controller;
use app\BaseController; //基础控制类
use think\facade\Config; //门面配置类
use think\facade\Db; //
class Test extends BaseController{
//原生查 query() 方法 -查询
public function query(){
$sql = "SELECT `name`,`sex`,`age` FROM `stud` WHERE id< 10";
$res = Db::query($sql);
echo "<pre>";
print_r($res);
}
//原生 新增 execute()方法 --执行
public function into (){
$sql = "INSERT INTO `stud` (`name`,`sex`,`age`,`salary`) VALUES ('王小二',0,99,'9999')";
$res = Db::execute($sql);
echo "<pre>";
print_r($res);
}
//原生 更新 execute()方法 --执行
public function set (){
$sql = "UPDATE `stud` SET `salary` = '9999',`name`='王小二' WHERE `id`=13";
$res = Db::execute($sql);
echo "<pre>";
print_r($res);
}
////原生 删除 execute()方法 --执行
public function del (){
$sql = "DELETE FROM `stud` WHERE `id`=13";
$res = Db::execute($sql);
echo "<pre>";
print_r($res);
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号