您好,登錄后才能下訂單哦!
小編給大家分享一下thinkphp6.0.2實(shí)現(xiàn)對(duì)數(shù)據(jù)庫操作的示例,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
因?yàn)榘姹靖聦?dǎo)致有些沒入門的同學(xué)學(xué)習(xí)thinkphp6出現(xiàn)問題,在這里保留我學(xué)習(xí)的一點(diǎn)經(jīng)驗(yàn)!
這是app/contrlar/目錄下新建的文件DbTest
<?php
namespace app\controller;//要讓其控制器顯示
use think\facade\Db;//使用哪個(gè)基類要包含其路徑class DbTest
{
public function demo1()
{
//原生查詢的讀操作query()
$sql=“SELECT user_id,name,age,email FROM user WHERE age>:age LIMIT :num”;
$map=array(“age”=>20,‘num’=>3);
sql,a);
}
public function demo2()
{
//原生查詢的寫操作execute()
$sql=“UPDATE user SET age=:age WHERE user_id=:id”;
$map=array(“age”=>20,‘id’=>3);
sql,a.‘條數(shù)據(jù)!’;
}
//查詢構(gòu)造器
//table()設(shè)置數(shù)據(jù)表
//field()設(shè)置查詢字段列表
//select()返回滿足條件的多條記錄
//find()返回滿足條件的第一條參數(shù)
public function demo3()
{
res);
}
//where()設(shè)置查詢條件,參數(shù)包括字符串,表達(dá)式,數(shù)組
//fetchsql():true,false
public function demo4()
{
res);
}?>
比起以往版本這個(gè)無需設(shè)置路由,數(shù)據(jù)庫也有原生文檔Env可以修改,想要添加新文檔首先在config/app.php里面將應(yīng)用變量指向你的新文檔然后打開瀏覽器輸入:
服務(wù)器名/類名/函數(shù)名/
即可訪問了
以上是“thinkphp6.0.2實(shí)現(xiàn)對(duì)數(shù)據(jù)庫操作的示例”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。