好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁(yè) > 知識(shí)庫(kù) > tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例

tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例

熱門標(biāo)簽:打開百度地圖標(biāo)注 海南外呼系統(tǒng)方案 蘇州外呼系統(tǒng)有效果嗎 地圖標(biāo)注怎么做商戶驗(yàn)證 山東電銷卡外呼系統(tǒng)原理是什么 400 電話 辦理 智能電銷語(yǔ)音機(jī)器人資訊 亳州企業(yè)外呼系統(tǒng) 兼職做地圖標(biāo)注好賺錢嗎

本文實(shí)例講述了thinkPHP5框架連接數(shù)據(jù)庫(kù)的方法。分享給大家供大家參考,具體如下:

1、配置文件目錄 tp5\application\database.php

通過配置文件來連接。。

也可以通過方法鏈接

在控制器里方法鏈接數(shù)據(jù)庫(kù) ;查詢時(shí)寫法 和使用系統(tǒng)的DB類方法略有差異

  // 使用方法配置數(shù)據(jù)庫(kù)連接
  public function data1 ()
  {
    $DB = Db::connect([
      // 數(shù)據(jù)庫(kù)類型
      'type'      => 'mysql',
      // 服務(wù)器地址
      'hostname'    => '127.0.0.1',
      // 數(shù)據(jù)庫(kù)名
      'database'    => 'user',
      // 用戶名
      'username'    => 'root',
      // 密碼
      'password'    => 'root',
      // 端口
      'hostport'    => '3306',
    ]);
    // dump($DB);
    // 查詢數(shù)據(jù),,,,和使用系統(tǒng)的DB類方法略有差異
    $data = $DB -> table("uu") -> select();
    dump($data);
  }

2.基本使用 、 增刪改查

控制器使用配置文件連接數(shù)據(jù)庫(kù)

控制器下文件(tp5\application\index\controller\Index.php)寫入

?php
namespace app\index\controller;
use think\Db;
use think\Controller;
class Index extends Controller
{
  public function index()
  {
    // return '上課來';
    return $this -> fetch();
  }
  // 使用配置文件連接數(shù)據(jù)庫(kù)
  public function data()
  {
    // 實(shí)例化數(shù)據(jù)庫(kù)系統(tǒng)類
    $DB = new Db;
    // 查詢數(shù)據(jù),表名為uu的所有數(shù)據(jù)
    $data = $DB::table("uu") -> select();
    // 使用sql語(yǔ)句
    //$data = $DB::query("select * from uu");
    dump($data);
  }
}

http://yourwebname/public/index.php/index/Index/data 獲取數(shù)據(jù)打印測(cè)試

3.將數(shù)據(jù)渲染模板頁(yè)面

?php
namespace app\index\controller;
use think\Db;
use think\Controller;
// 使用model連接數(shù)據(jù)庫(kù)要引入moadel
use think\Model;
class Index extends Controller
{
  public function index()
  {
    // return 's';
    $this -> data();
    return $this -> fetch();
  }
// 使用系統(tǒng)配置文件連接數(shù)據(jù)庫(kù)
  public function data()
  {
    // 實(shí)例化數(shù)據(jù)庫(kù)系統(tǒng)類
    $DB = new Db;
    // 查詢數(shù)據(jù)
    $data = $DB::table("uu") -> select();
    $this -> assign("user",$data);
    // dump($data);
  }
}

4.模板頁(yè)面即可引用渲染數(shù)據(jù)

tp5\application\index\view\index\index.html

!DOCTYPE html>
html lang="en">
head>
  meta charset="UTF-8">
  title>s/title>
/head>
body>
  div> s/div>
  {volist name="user" id="vo"}
    a href="">{$vo.name}/a>
  {/volist}
/body>
/html>

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • tp5.1 框架數(shù)據(jù)庫(kù)高級(jí)查詢技巧實(shí)例總結(jié)
  • ThinkPHP5.1框架數(shù)據(jù)庫(kù)鏈接和增刪改查操作示例
  • PHP利用pdo_odbc實(shí)現(xiàn)連接數(shù)據(jù)庫(kù)示例【基于ThinkPHP5.1搭建的項(xiàng)目】
  • PHP7使用ODBC連接SQL Server2008 R2數(shù)據(jù)庫(kù)示例【基于thinkPHP5.1框架】
  • thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫(kù)并返回json數(shù)據(jù)實(shí)例
  • tp5(thinkPHP5)框架數(shù)據(jù)庫(kù)Db增刪改查常見操作總結(jié)
  • tp5(thinkPHP5)框架實(shí)現(xiàn)多數(shù)據(jù)庫(kù)查詢的方法
  • tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫(kù)的方法
  • thinkPHP5實(shí)現(xiàn)數(shù)據(jù)庫(kù)添加內(nèi)容的方法
  • thinkPHP5框架數(shù)據(jù)庫(kù)連貫操作之cache()用法分析
  • thinkPHP5框架實(shí)現(xiàn)多數(shù)據(jù)庫(kù)連接,跨數(shù)據(jù)連接查詢操作示例
  • tp5.1 框架數(shù)據(jù)庫(kù)常見操作詳解【添加、刪除、更新、查詢】

標(biāo)簽:呼倫貝爾 萊蕪 紹興 溫州 金華 清遠(yuǎn) 安康 綏化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例》,本文關(guān)鍵詞  tp5,thinkPHP5,框架,連接,數(shù)據(jù)庫(kù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于tp5(thinkPHP5)框架連接數(shù)據(jù)庫(kù)的方法示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章