久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>

                            主站蜘蛛池模板: 一区二区三区中文 | 国产精品成人一区二区三区 | 视频在线观看一区二区 | 天堂在线中文字幕 | 欧美在线a | 精品久久久久久久人人人人传媒 | 国产成人免费视频 | 国产伦精品一区二区三区高清 | av在线免费观看网站 | 91精品国产综合久久香蕉922 | 国产成人黄色 | 日韩久久精品电影 | 亚洲免费视频一区二区 | 久久久久久国产免费视网址 | 孕妇一级毛片 | 91在线视频免费观看 | 国产福利观看 | 成人午夜影院 | 精品久久久久久亚洲精品 | 激情av免费看| 久久久久国产一区二区三区 | 国产久 | 日韩欧美一区二区三区在线播放 | 久久久久久久久久久久久9999 | 成人夜晚看av | 国产情侣啪啪 | 九九国产 | 在线看h| 国产精品国产成人国产三级 | 男女搞网站 | 成人免费高清 | 在线视频一区二区三区 | 日韩精品亚洲专区在线观看 | 成人在线精品视频 | 成人精品 | 精品香蕉一区二区三区 | 久久久久亚洲精品中文字幕 | 欧美jizzhd精品欧美巨大免费 | 欧美精品久久久久久久久老牛影院 | 国产一区二区三区四区三区四 | 欧美a在线看 |