<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 插入數據庫 先引入Db類 ~~~ use think\Db; ~~~ ## 語法: ## Db::table('表名')->insert(); ``` $data=['user_name'=>'zhangxueyou','password'=>'123456']; 數據庫字段名=>字段值 ``` ## insert()方法返回值為影響幾行 insert方法添加數據成功返回添加成功的條數,insert正常情況返回1 ## 返回值: ![](https://img.kancloud.cn/de/a0/dea0c8f958d6d40f7dbd11cf22578d14_946x390.png) ## 語法截圖: ![](https://img.kancloud.cn/e2/0f/e20f3f45931a1fa17234c48ae7e61375_1228x516.png) ## 語法: ~~~ <?php namespace app\index\controller; use think\Controller; use think\Db; class Index extends Controller { public function index(){ $data=['user_name'=>'zhangxueyou','password'=>'123456']; // $res= Db::table('guo_maik')->insert($data); //表名要帶上前綴guo_ $res=Db::name('maik')->insert($data); //表名可以不帶前綴 dump($res); } } ~~~ # 獲取自增ID插入后 ## 語法: ## $id=Db::name('user')->getLastlnslD(); ## 返回值:獲取當前自增的ID值 (插入值的ID) ![](https://img.kancloud.cn/15/8c/158c1f1dc1486cde62bbea298b6d095a_1347x576.png) ## 代碼案例: ~~~ <?php namespace app\index\controller; use think\Controller; use think\Db; class Index extends Controller { public function index(){ $data=['user_name'=>'zhangxueyou','password'=>'123456']; // $res= Db::table('guo_maik')->insert($data); //表名要帶上前綴guo_ $res=Db::name('maik')->insert($data); //表名可以不帶前綴 dump($res); $id=Db::name('user')->getLastInsID(); dump($id); } } ~~~ # 插入多條數據 Db::name('maik')->insertAll($data); 把單條中insert()方法換成insertAll()方法就可以實現多條數據插入 ![](https://img.kancloud.cn/53/77/537745a6dd0b9710a26c27d26747ecbf_1231x665.png) ## $data寫成二維數組的方式 ![](https://img.kancloud.cn/ce/df/cedfe2cd32a2124912571f5c2db935cd_1066x312.png) ## 代碼案例: ~~~ <?php namespace app\index\controller; use think\Controller; use think\Db; class Index extends Controller { public function index(){ $data=[ ['user_name'=>'zhangxueyou','password'=>'123456'], ['user_name'=>'zhang','password'=>'123'], ['user_name'=>'yyyert','password'=>'dd33'] ]; // $res= Db::table('guo_maik')->insert($data); //表名要帶上前綴guo_ $res=Db::name('maik')->insertAll($data); //表名可以不帶前綴 dump($res); $id=Db::name('user')->getLastInsID(); dump($id); } } ~~~ 數據庫值 ![](https://img.kancloud.cn/64/1f/641f9421b12a868f1cbd03cafc982a9f_1236x704.png) # 獲取插入的ID方法 Db::table('guo_maik')->insert($data,'',true); 的情況下返回的則是這條數據的ID ![](https://img.kancloud.cn/68/d4/68d468089daa573b261044c852b89df3_1357x590.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看