婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > PHP tp5中使用原生sql查詢代碼實例

PHP tp5中使用原生sql查詢代碼實例

熱門標簽:黔江400電話如何辦理 招標自動語音外呼系統(tǒng) OMG地圖標注app 地圖標注視頻廣告入駐 gps 地圖標注軟件 電銷機器人便宜的有嗎 400電話鄭州申請 中原區(qū)電話機器人價格 ai電話機器人加盟代理

注意事項:

1.先在database.php中配置好數(shù)據(jù)庫

2.只要是數(shù)據(jù)庫操作必須引用 use/think/Db;嚴格區(qū)分大小寫。

下面是方法:

 public function hello5()
  {
    //所有查詢必須 use/think/Db;
    /* 1 配置數(shù)據(jù)庫
     * 2 使用DB 命名空間
     * 
     */ 
    
    /****************tp5中使用原生語句*******************/
    //query 用于查詢 其他的用execute
    
    // 插入記錄
//     $result = Db::execute('insert into sb_ad (ad_name, ad_content ,status) values (1, "456",1)');
//     dump($result);  
    // 更新記錄
//    $result = Db::execute('update sb_ad set ad_name = "framework" where ad_id = 1 ');
//    dump($result);    
    // 查詢數(shù)據(jù)
//    $result = Db::query('select * from sb_ad where ad_id = 1');
//    print_r($result);
    // 刪除數(shù)據(jù)
//     $result = Db::execute('delete from sb_ad where ad_id = 2 ');
//     dump($result);   
    //其它操作
    // 顯示數(shù)據(jù)庫列表
//    $result = Db::query('show tables from tpshop1');
//    print_r($result);
//     清空數(shù)據(jù)表
//     $result = Db::execute('TRUNCATE table sb_ad');
//     dump($result);

    /**************多個數(shù)據(jù)庫操作************/
    //在application/config.php中加入配置
    //例子:
    /*
     * // 數(shù)據(jù)庫配置1
        'db2'  => [
          // 數(shù)據(jù)庫類型
          'type'   => 'mysql',
          // 服務器地址
          'hostname' => '127.0.0.1',
          // 數(shù)據(jù)庫名
          'database' => 'tpshop2',
          // 數(shù)據(jù)庫用戶名
          'username' => 'root',
          // 數(shù)據(jù)庫密碼
          'password' => '',
          // 數(shù)據(jù)庫連接端口
          'hostport' => '',
          // 數(shù)據(jù)庫連接參數(shù)
          'params'  => [],
          // 數(shù)據(jù)庫編碼默認采用utf8
          'charset' => 'utf8',
          // 數(shù)據(jù)庫表前綴
          'prefix'  => 'tp_',
        ],
        依次類推
     */
    //connect為鏈接數(shù)據(jù)庫
//     $result = Db::connect('db2')->query('select * from sb_ad where ad_id = 1');
//     print_r($result);

//     $result = Db::connect('db3')->query('select * from sb_ad where ad_id = 1');    
//     print_r($result);  
    
//    $db1 = Db::connect('db1');獲取數(shù)據(jù)庫對象
//    $db2 = Db::connect('db2');獲取數(shù)據(jù)庫對象然后再操作
//    $db1->query('select * from sb_ad where ad_id = 1');
//    $db2->query('select * from sb_ad where ad_id = 1');
     
    
    /*****參數(shù)綁定******/
//    Db::execute('insert into sb_ad (ad_name, ad_content ,status) values (?, ?, ?)', [3, 'thinkphp', 1]);
//    $result = Db::query('select * from sb_ad where ad_id = ?', [3]);
//    print_r($result);  
    /******命名占位符綁定*****/
//    Db::execute('insert into sb_ad (ad_name, ad_content ,status) values (:ad_name, :ad_content, :status)', ['ad_name' => 11, 'ad_content' => 'thinkphp', 'status' => 1]);
//    $result = Db::query('select * from sb_ad where ad_id=:id', ['id' => 10]);
//    print_r($result);

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • tp5.1 框架數(shù)據(jù)庫-數(shù)據(jù)集操作實例分析
  • tp5.1 框架路由操作-URL生成實例分析
  • tp5.1 框架join方法用法實例分析
  • tp5.1框架數(shù)據(jù)庫子查詢操作實例分析
  • tp5.1 框架數(shù)據(jù)庫常見操作詳解【添加、刪除、更新、查詢】
  • TP5多入口設(shè)置實例講解

標簽:哈密 孝感 北京 阿里 池州 日照 那曲 濟源

巨人網(wǎng)絡(luò)通訊聲明:本文標題《PHP tp5中使用原生sql查詢代碼實例》,本文關(guān)鍵詞  PHP,tp5,中,使用,原生,sql,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP tp5中使用原生sql查詢代碼實例》相關(guān)的同類信息!
  • 本頁收集關(guān)于PHP tp5中使用原生sql查詢代碼實例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 四子王旗| 文山县| 大丰市| 长宁区| 什邡市| 莲花县| 儋州市| 岗巴县| 湟源县| 鸡泽县| 武宣县| 乐山市| 仲巴县| 潮安县| 荃湾区| 曲阜市| 罗田县| 武邑县| 蒙自县| 息烽县| 垦利县| 资溪县| 峨边| 区。| 平远县| 新建县| 乌兰浩特市| 宁乡县| 江都市| 桃园县| 旌德县| 平乡县| 晋江市| 昆明市| 赤壁市| 长武县| 香港| 来凤县| 凤凰县| 上饶县| 旺苍县|