天天看點

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>