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

      <i id='1OmPv'><tr id='1OmPv'><dt id='1OmPv'><q id='1OmPv'><span id='1OmPv'><b id='1OmPv'><form id='1OmPv'><ins id='1OmPv'></ins><ul id='1OmPv'></ul><sub id='1OmPv'></sub></form><legend id='1OmPv'></legend><bdo id='1OmPv'><pre id='1OmPv'><center id='1OmPv'></center></pre></bdo></b><th id='1OmPv'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1OmPv'><tfoot id='1OmPv'></tfoot><dl id='1OmPv'><fieldset id='1OmPv'></fieldset></dl></div>

      <small id='1OmPv'></small><noframes id='1OmPv'>

    1. <tfoot id='1OmPv'></tfoot>

      1. <legend id='1OmPv'><style id='1OmPv'><dir id='1OmPv'><q id='1OmPv'></q></dir></style></legend>

        • <bdo id='1OmPv'></bdo><ul id='1OmPv'></ul>
      2. PDO lastInsertId() 總是返回 0

        PDO lastInsertId() always return 0(PDO lastInsertId() 總是返回 0)

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

                  <tbody id='eE7Ne'></tbody>

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

                  本文介紹了PDO lastInsertId() 總是返回 0的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我遇到了一個問題.我的框架在 PHP 5.3.0 上工作得很好.我將 PHP 版本升級到 PHP 5.4.x,并且我的框架的某些部分開始出現(xiàn)一些問題.

                  I've come across with a problem. My framework was working just fine with PHP 5.3.0. I upgraded my PHP version to PHP 5.4.x and I started to have few issues with some parts of my framework.

                  PHP版本升級后,PDO lastInsterId()總是返回0.

                  After PHP version upgrade, PDO lastInsterId() always returns 0.

                  我有一個名為 id 的自增字段.它正在將數(shù)據(jù)添加到數(shù)據(jù)庫中,沒有任何問題.

                  I have auto-increment field called id. It is adding the data to database without any problems.

                  出于某種原因,我一直將 0 作為最后一個插入 id.

                  For some reason I keep getting 0 as last insert id.

                  這是我的代碼;

                  databaseobjects.php

                  public static function create () {
                          global $db;
                          $attributes = self::sanitize(static::$fields);
                  
                          $sql  = "INSERT INTO ".PREFIX.static::$table_name." (";
                          $sql .= join(", ", array_keys($attributes));
                          $sql .= ") VALUE (:";
                          $sql .= join(", :", array_keys($attributes));
                          $sql .= ")";
                  
                          return ($db->crudQuery($sql, $attributes)) ? true : false;
                      }
                  
                  public static function lastInsertID () {
                          global $db;
                          return $db->handler->lastInsertId();
                      }
                  

                  database.php

                  public function crudQuery($sql, $data) {
                          $sth = $this->handler->prepare($sql);
                          return $sth->execute($data);
                      }
                  

                  首先調(diào)用create()方法,然后調(diào)用crudQuery()方法.正如我之前提到的,我可以成功地將數(shù)據(jù)添加到 MySQL 數(shù)據(jù)庫中.不幸的是,當我調(diào)用 lastInsterID() 方法時,它總是返回 0.

                  First create() method is called, then crudQuery() method is called. As I mentioned before, I can add the data successfully to MySQL database. Unfortunately when I call lastInsterID() method, it always returns 0.

                  如果您能在我使用 SQL 查詢獲得最后一個 ID 之前幫我解決這個問題,我將非常高興 (:

                  I will be really glad if you can help me out with this problem before I will get the last ID with SQL Query (:

                  推薦答案

                  除了 php/PDO 或您的框架中的錯誤之外,還有兩種可能性.lastInsertId() 在與插入不同的 MySQL 連接上調(diào)用,或者您在應(yīng)用程序/框架中生成 id 并插入它,而不是讓 auto_increment 為您生成它.表中哪一列是主鍵/auto_increment?該列是否包含在 create() 函數(shù)的 $attributes 中?

                  Other than a bug in php/PDO or your framework, there are two possibilities. Either lastInsertId() is called on a different MySQL connection than the insert, or you are generating the id in your application/framework and inserting it, rather than letting auto_increment generate it for you. Which column in the table is the primary key/auto_increment? Is that column included in $attributes in your create() function?

                  您可以測試 PDO 以確保該部分使用此代碼(在新文件中)正常工作:

                  You can test PDO to make sure that part is working correctly with this code (in a new file):

                  // Replace the database connection information, username and password with your own.
                  $conn = new PDO('mysql:dbname=test;host=127.0.0.1', 'user', 'password');
                  
                  $conn->exec('CREATE TABLE testIncrement ' .
                              '(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50))');
                  $sth = $conn->prepare('INSERT INTO testIncrement (name) VALUES (:name)');
                  $sth->execute([':name' => 'foo']);
                  var_dump($conn->lastInsertId());
                  $conn->exec('DROP TABLE testIncrement');
                  

                  當我運行這個腳本時,輸出是

                  When I ran this script, the output was

                  string(1) "1"
                  

                  這篇關(guān)于PDO lastInsertId() 總是返回 0的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)
                • <tfoot id='FtElN'></tfoot>
                  <i id='FtElN'><tr id='FtElN'><dt id='FtElN'><q id='FtElN'><span id='FtElN'><b id='FtElN'><form id='FtElN'><ins id='FtElN'></ins><ul id='FtElN'></ul><sub id='FtElN'></sub></form><legend id='FtElN'></legend><bdo id='FtElN'><pre id='FtElN'><center id='FtElN'></center></pre></bdo></b><th id='FtElN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FtElN'><tfoot id='FtElN'></tfoot><dl id='FtElN'><fieldset id='FtElN'></fieldset></dl></div>

                  <legend id='FtElN'><style id='FtElN'><dir id='FtElN'><q id='FtElN'></q></dir></style></legend>
                        <tbody id='FtElN'></tbody>
                    • <small id='FtElN'></small><noframes id='FtElN'>

                          • <bdo id='FtElN'></bdo><ul id='FtElN'></ul>
                            主站蜘蛛池模板: 久久99蜜桃综合影院免费观看 | 羞羞视频在线观看网站 | 天天躁天天操 | 干狠狠 | 国产色99 | 欧美日韩精品一区二区三区视频 | 久久免费精品视频 | 美女网站视频免费黄 | 久久精品欧美一区二区三区不卡 | 精品国产99 | 日韩精品久久一区二区三区 | 日日碰碰| 免费视频二区 | 亚洲视频欧美视频 | 国产高清在线精品一区二区三区 | 亚洲日韩中文字幕一区 | 精品久久久久久亚洲精品 | 亚洲精选久久 | 国产一区二区精品在线观看 | 亚洲一区二区三区国产 | 在线观看国产wwwa级羞羞视频 | 国产 日韩 欧美 制服 另类 | 免费国产一区 | 91文字幕巨乱亚洲香蕉 | 一级片子 | 夜夜爽夜夜操 | 一级毛片网 | 精品99久久 | 欧美一级黄色免费看 | 日韩精品一二三 | 国产精品久久久久久吹潮 | 国产激情视频在线 | 欧美一级一区 | 天天综合日日夜夜 | 在线成人精品视频 | 成人欧美一区二区三区1314 | 性一交一乱一伦视频免费观看 | 欧美日韩大片 | 久久精品亚洲精品国产欧美 | 黄色毛片黄色毛片 | 欧美成人一区二区三区 |