亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁/技術文章
文章詳情頁

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

瀏覽:82日期:2022-09-08 18:19:36

注意事項:

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);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: PHP
相關文章:
主站蜘蛛池模板: 国产精品公开免费视频 | 黄色不卡视频 | 国产呦精品系列在线 | 一级一级特黄女人精品毛片视频 | 亚色一区 | 欧美日韩一区二区三区色综合 | 视频播放在线观看精品视频 | 九九色综合 | 免费jizz在在线播放国产 | 亚洲日本人成中文字幕 | 国产日产欧美精品一区二区三区 | 亚洲精品高清国产一线久久97 | 91久久精品日日躁夜夜躁欧美 | 欧美成人性色xxxx视频 | 免费一区二区 | 91成人影院未满十八勿入 | 日本乱人伦片中文三区 | 中国一级毛片免费观看 | 免费观看a级毛片在线播放 免费观看a级片 | 一国产一级淫片a免费播放口 | 国产制服 国产制服一区二区 | 三级毛片在线 | 国产一级特黄aa大片爽爽 | 在线观看黄色 | 达达兔欧美午夜国产亚洲 | 免费在线播放黄色 | 成人国产视频在线观看 | 99毛片| 欧美亚洲一区二区三区在线 | 黄p片| 亚洲欧美另类精品久久久 | 久久久久久国产精品免费免 | 国产微拍精品 | 国产精品2022不卡在线观看 | 亚洲人成网站在线播放观看 | 美女拍拍拍免费视频观看 | 1024.1024亚洲 国产 图片 1024cao社区榴地址一地址二 | 色综合久久中文综合网 | 1313午夜精品久久午夜片 | 天天影视色香欲综合网老头 | 亚洲精品中文字幕乱码一区二区 |