Blogger Information
Blog 49
fans 2
comment 1
visits 22144
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
08-13作业:实现TP中的数据库原生操作
子傅
Original
690 people have browsed it

TP多例模式的设置

1、config 文件夹下的config 多例配置

2、controller 文件放到新项目文件夹下,需调整原有的命名空间,如原命名空间为 app\controller 需要改为 app\新文件夹名\controller 


实例

<?php
/**
 * Created by PhpStorm.
 * User: A
 * Date: 2019-08-14
 * Time: 2:14
 */
namespace app\testSQL\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 `staff` WHERE id< 10";
       $res = Db::query($sql);
       echo "<pre>";
       print_r($res);
    }
    //原生 新增 execute()方法  --执行
    public function into (){
        $sql = "INSERT INTO `staff` (`name`,`sex`,`age`,`salary`) VALUES ('龙王',0,99,'8888')";
        $res = Db::execute($sql);
        echo "<pre>";
        print_r($res);
    }

    //原生 更新 execute()方法  --执行
    public function set (){
        $sql = "UPDATE `staff` SET `salary` = '8899',`name`='老龙王' WHERE `id`=223";
        $res = Db::execute($sql);
        echo "<pre>";
        print_r($res);
    }

    ////原生 删除 execute()方法  --执行
    public function del (){
        $sql = "DELETE FROM `staff` WHERE `id`=223";
        $res = Db::execute($sql);
        echo "<pre>";
        print_r($res);
    }
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:完成的不错。
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post