Blogger Information
Blog 32
fans 0
comment 0
visits 22558
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
08-13作业:实现TP6数据库增删查改语句、表达式语句
Yx的博客
Original
1096 people have browsed it

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);
    }
}

运行实例 »

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


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