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

      <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="tnlr5n5" 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="nlrhj5b" 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,并且我的框架的某些部分開始出現一些問題.

                  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 的自增字段.它正在將數據添加到數據庫中,沒有任何問題.

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

                  首先調用create()方法,然后調用crudQuery()方法.正如我之前提到的,我可以成功地將數據添加到 MySQL 數據庫中.不幸的是,當我調用 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 連接上調用,或者您在應用程序/框架中生成 id 并插入它,而不是讓 auto_increment 為您生成它.表中哪一列是主鍵/auto_increment?該列是否包含在 create() 函數的 $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"
                  

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

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                • <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="rlvzdjh" 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>
                            主站蜘蛛池模板: 昆明挖掘机修理厂_挖掘机翻新再制造-昆明聚力工程机械维修有限公司 | 气象监测系统_气象传感器_微型气象仪_气象环境监测仪-山东风途物联网 | 湖南教师资格网-湖南教师资格证考试网 | 空气能采暖,热泵烘干机,空气源热水机组|设备|厂家,东莞高温热泵_正旭新能源 | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 精密交叉滚子轴承厂家,转盘轴承,YRT转台轴承-洛阳千协轴承 | 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 苏州同创电子有限公司 - 四探针测试仪源头厂家 | 幂简集成 - 品种超全的API接口平台, 一站搜索、试用、集成国内外API接口 | 精密机械零件加工_CNC加工_精密加工_数控车床加工_精密机械加工_机械零部件加工厂 | 湖南自考_湖南自学考试| 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | 渣土车电机,太阳能跟踪器电机,蜗轮蜗杆减速电机厂家-淄博传强电机 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 蓝鹏测控平台 - 智慧车间系统 - 车间生产数据采集与分析系统 | 全自动定氮仪-半自动凯氏定氮仪厂家-祎鸿仪器 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 喷涂流水线,涂装流水线,喷漆流水线-山东天意设备科技有限公司 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 地磅-地秤-江阴/无锡地磅-江阴天亿计量设备有限公司_ | 火锅加盟_四川成都火锅店加盟_中国火锅连锁品牌十强_朝天门火锅【官网】 | 冷藏车-东风吸污车-纯电动环卫车-污水净化车-应急特勤保障车-程力专汽厂家-程力专用汽车股份有限公司销售二十一分公司 | 真空上料机(一种真空输送机)-百科 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 汝成内控-行政事业单位内部控制管理服务商 | 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 微波萃取合成仪-电热消解器价格-北京安合美诚科学仪器有限公司 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 佛山市钱丰金属不锈钢蜂窝板定制厂家|不锈钢装饰线条|不锈钢屏风| 电梯装饰板|不锈钢蜂窝板不锈钢工艺板材厂家佛山市钱丰金属制品有限公司 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 优宝-汽车润滑脂-轴承润滑脂-高温齿轮润滑油脂厂家 | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 脱硫搅拌器厂家-淄博友胜不锈钢搅拌器厂家 | 全自动翻转振荡器-浸出式水平振荡器厂家-土壤干燥箱价格-常州普天仪器 | GAST/BRIWATEC/CINCINNATI/KARL-KLEIN/ZIEHL-ABEGG风机|亚喜科技 | 单锥双螺旋混合机_双螺旋锥形混合机-无锡新洋设备科技有限公司 | 刑事律师_深圳著名刑事辩护律师_王平聚【清华博士|刑法教授】 | 阻垢剂-反渗透缓蚀阻垢剂厂家-山东鲁东环保科技有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 |