天天看点

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 学习

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

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 二表关联查询 

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>