pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='gjCYz'><style id='gjCYz'><dir id='gjCYz'><q id='gjCYz'></q></dir></style></legend>
      1. <i id='gjCYz'><tr id='gjCYz'><dt id='gjCYz'><q id='gjCYz'><span id='gjCYz'><b id='gjCYz'><form id='gjCYz'><ins id='gjCYz'></ins><ul id='gjCYz'></ul><sub id='gjCYz'></sub></form><legend id='gjCYz'></legend><bdo id='gjCYz'><pre id='gjCYz'><center id='gjCYz'></center></pre></bdo></b><th id='gjCYz'></th></span></q></dt></tr></i><div class="u2u2exo" id='gjCYz'><tfoot id='gjCYz'></tfoot><dl id='gjCYz'><fieldset id='gjCYz'></fieldset></dl></div>

          <bdo id='gjCYz'></bdo><ul id='gjCYz'></ul>
      2. <tfoot id='gjCYz'></tfoot>

        <small id='gjCYz'></small><noframes id='gjCYz'>

        如何從 PDO 獲取最后插入的插入行 ID

        How to get last inserted inserted row id from PDO(如何從 PDO 獲取最后插入的插入行 ID)

        <small id='JckDW'></small><noframes id='JckDW'>

          • <bdo id='JckDW'></bdo><ul id='JckDW'></ul>
                  <tbody id='JckDW'></tbody>
                  <legend id='JckDW'><style id='JckDW'><dir id='JckDW'><q id='JckDW'></q></dir></style></legend><tfoot id='JckDW'></tfoot>

                  <i id='JckDW'><tr id='JckDW'><dt id='JckDW'><q id='JckDW'><span id='JckDW'><b id='JckDW'><form id='JckDW'><ins id='JckDW'></ins><ul id='JckDW'></ul><sub id='JckDW'></sub></form><legend id='JckDW'></legend><bdo id='JckDW'><pre id='JckDW'><center id='JckDW'></center></pre></bdo></b><th id='JckDW'></th></span></q></dt></tr></i><div class="yxhkf8l" id='JckDW'><tfoot id='JckDW'></tfoot><dl id='JckDW'><fieldset id='JckDW'></fieldset></dl></div>
                  本文介紹了如何從 PDO 獲取最后插入的插入行 ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在 PHP 中遵循 mvc 結構,我想檢索最后插入的行 ID.

                  I am following mvc structure in PHP and I want to retrieve last inserted row ID.

                  我創建了以下 sql 代碼:

                  $sql = "INSERT INTO song (artist, track, link) VALUES (:artist, :track, :link)";
                  $query = $this->db->prepare($sql);
                  $query->execute(array(':artist' => $artist, ':track' => $track, ':link' => $link));
                  
                  echo $query->lastInsertId(); // To retrieve last inserted row ID.
                  

                  但不幸的是我收到了這個錯誤:致命錯誤:調用未定義的方法 PDOStatement::lastInsertId()

                  but unfortunately I ma getting this error: Fatal error: Call to undefined method PDOStatement::lastInsertId()

                  我也試過這個 stack 鏈接,但對我不起作用,所以如果你幫我檢索 ID,我會很高興.

                  I have also tried this stack links but not worked for me so I will happy if you help me for retrieve ID.

                  我也在這里分享我的 controller.php 文件.

                  I am also sharing my controller.php file here.

                  /**
                   * This is the "base controller class". All other "real" controllers extend this class.
                   */
                  class Controller{
                      /**
                       * @var null Database Connection
                       */
                      public $db = null;
                  
                      /**
                       * Whenever a controller is created, open a database connection too. The idea behind is to have ONE connection
                       * that can be used by multiple models (there are frameworks that open one connection per model).
                       */
                      function __construct(){
                          $this->openDatabaseConnection();
                      }
                  
                      /**
                       * Open the database connection with the credentials from application/config/config.php
                       */
                      private function openDatabaseConnection(){
                          // set the (optional) options of the PDO connection. in this case, we set the fetch mode to
                          // "objects", which means all results will be objects, like this: $result->user_name !
                          // For example, fetch mode FETCH_ASSOC would return results like this: $result["user_name] !
                          // @see http://www.php.net/manual/en/pdostatement.fetch.php
                          $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
                  
                          // generate a database connection, using the PDO connector
                          // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
                          $this->db = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS, $options);
                      }
                  
                      /**
                       * Load the model with the given name.
                       * loadModel("SongModel") would include models/songmodel.php and create the object in the controller, like this:
                       * $songs_model = $this->loadModel('SongsModel');
                       * Note that the model class name is written in "CamelCase", the model's filename is the same in lowercase letters
                       * @param string $model_name The name of the model
                       * @return object model
                       */
                      public function loadModel($model_name){
                          require 'application/models/' . strtolower($model_name) . '.php';
                          // return new model (and pass the database connection to the model)
                          return new $model_name($this->db);
                      }
                  }
                  

                  推薦答案

                  大功告成.

                  如果您查看 lastInsertId 的手冊頁,則會在數據庫句柄 - 您當前正在語句中調用它.

                  If you look at the manual page for lastInsertId, it's called on the database handle - you're currently calling it on the statement.

                  你只需要打電話:

                  $this->db->lastInsertId();
                  

                  這篇關于如何從 PDO 獲取最后插入的插入行 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                    <small id='mBTiO'></small><noframes id='mBTiO'>

                        <legend id='mBTiO'><style id='mBTiO'><dir id='mBTiO'><q id='mBTiO'></q></dir></style></legend>
                      1. <i id='mBTiO'><tr id='mBTiO'><dt id='mBTiO'><q id='mBTiO'><span id='mBTiO'><b id='mBTiO'><form id='mBTiO'><ins id='mBTiO'></ins><ul id='mBTiO'></ul><sub id='mBTiO'></sub></form><legend id='mBTiO'></legend><bdo id='mBTiO'><pre id='mBTiO'><center id='mBTiO'></center></pre></bdo></b><th id='mBTiO'></th></span></q></dt></tr></i><div class="8ywvoqh" id='mBTiO'><tfoot id='mBTiO'></tfoot><dl id='mBTiO'><fieldset id='mBTiO'></fieldset></dl></div>
                          <bdo id='mBTiO'></bdo><ul id='mBTiO'></ul>
                        • <tfoot id='mBTiO'></tfoot>
                              <tbody id='mBTiO'></tbody>

                            主站蜘蛛池模板: 成都租车_成都租车公司_成都租车网_众行宝 | 电缆接头_防水接头_电缆防水接头_防水电缆接头_上海闵彬 | 智能门锁电机_智能门锁离合器_智能门锁电机厂家-温州劲力智能科技有限公司 | 真空泵厂家_真空泵机组_水环泵_旋片泵_罗茨泵_耐腐蚀防爆_中德制泵 | 展厅设计公司,展厅公司,展厅设计,展厅施工,展厅装修,企业展厅,展馆设计公司-深圳广州展厅设计公司 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业| 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 壹车网 | 第一时间提供新车_资讯_报价_图片_排行! | 翅片管换热器「型号全」_厂家-淄博鑫科环保 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 登车桥动力单元-非标液压泵站-非标液压系统-深圳市三好科技有限公司 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 防腐储罐_塑料储罐_PE储罐厂家_淄博富邦滚塑防腐设备科技有限公司 | 金属波纹补偿器厂家_不锈钢膨胀节价格_非金属伸缩节定制-庆达补偿器 | 船用泵,船用离心泵,船用喷射泵,泰州隆华船舶设备有限公司 | 中国在职研究生招生信息网 | 危废处理系统,水泥厂DCS集散控制系统,石灰窑设备自动化控制系统-淄博正展工控设备 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | 同学聚会纪念册制作_毕业相册制作-成都顺时针宣传画册设计公司 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | 学习安徽网 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 污水/卧式/潜水/钻井/矿用/大型/小型/泥浆泵,价格,参数,型号,厂家 - 安平县鼎千泵业制造厂 | 压缩空气冷冻式干燥机_吸附式干燥机_吸干机_沪盛冷干机 | 药品仓库用除湿机-变电站用防爆空调-油漆房用防爆空调-杭州特奥环保科技有限公司 | 齿轮减速机_齿轮减速电机-VEMT蜗轮蜗杆减速机马达生产厂家瓦玛特传动瑞环机电 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 涂层测厚仪_漆膜仪_光学透过率仪_十大创新厂家-果欧电子科技公司 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 河南凯邦机械制造有限公司 | 硬齿面减速机_厂家-山东安吉富传动设备股份有限公司 | 无机纤维喷涂棉-喷涂棉施工工程-山东华泉建筑工程有限公司▲ | 旗帜网络笔记-免费领取《旗帜网络笔记》电子书 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 厌氧工作站-通用型厌氧工作站-上海胜秋科学仪器有限公司 |