Tp5 学习

确认Tp5连接数据库

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index  extends  Controller
{
    public function index()
    {
        $res =Db::connect();
        dump($res);
    }
}


出现相关信息,连接成功。


tp5 阅读了增加 

 
use think\Controller;
use \think\Request;
use think\Db;
use think\Loader;


 public function  ceshi(){

        $name='小兰';

        $data=Db::name('ce')->where('name',$name)->field('click_num')->select();
         $click_num=$data[0]['click_num']; //12
        $click_nums=$click_num+1;
        $data=Db::name('ce')->where('name',$name)->setField('click_num',"$click_nums");
        //dump($data);die;
        if($data ===1){
            return 'true';
        }else{
            return 'false';
        }


    }

也可以用TP5 自带的自增+1 方法

 $datas =Db::name('tonghua')->where('id', $id)->setInc('click_num'); //点击率加1

// score 字段加 1
Db::table('think_user')->where('id', 1)->setInc('score');
// score 字段加 5
Db::table('think_user')->where('id', 1)->setInc('score', 5);
// score 字段减 1
Db::table('think_user')->where('id', 1)->setDec('score');
// score 字段减 5
Db::table('think_user')->where('id', 1)->setDec('score', 5);

TP5 简单的过滤设置

tp5 二表关联查询 

    

tp5 去除index.php  修改.htaccess 

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值