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

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

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

          <bdo id='pLudt'></bdo><ul id='pLudt'></ul>
        <legend id='pLudt'><style id='pLudt'><dir id='pLudt'><q id='pLudt'></q></dir></style></legend>

        <tfoot id='pLudt'></tfoot>

      1. PHP PDO 準備好的語句查詢不更新記錄

        PHP PDO Prepared statement query not updating record(PHP PDO 準備好的語句查詢不更新記錄)

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

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

          2. <tfoot id='fahVf'></tfoot>
              • <bdo id='fahVf'></bdo><ul id='fahVf'></ul>
                <legend id='fahVf'><style id='fahVf'><dir id='fahVf'><q id='fahVf'></q></dir></style></legend>
                    <tbody id='fahVf'></tbody>

                  本文介紹了PHP PDO 準備好的語句查詢不更新記錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在使用 PHP 的 PDO 對象準備更新語句和更新記錄時遇到問題.我已經獲取了原始 SQL 查詢并在 phpMyAdmin 中運行它,參數被傳遞給函數的值替換.它按預期更新記錄.但是,從腳本運行時,它不會更新.它拋出零錯誤并返回 00000 的 errorInfo() 回復,據我所知,這是 PDO 表示一切正常的方式.我知道 PDO 對象有效,因為它成功地從數據庫中插入和選擇記錄,包括我試圖更新的記錄.我知道這個更新功能很丑,我只是在學習 PDO.

                  顯然,這是用 PHP5 編碼的,使用 PDO.

                  類函數:

                  公共函數更新($tbl_name, $where = null, $what = null){if(is_array($w??here)){$where_str = '哪里';foreach($where as $key => $val){$where_str .= "{$key} = ':{$key}' 和 ";}$where_str = substr($where_str,0,-5);$what_str = '設置';foreach($what as $key => $val){$what_str .= "`{$key}` = ':{$key}', ";}$what_str = substr($what_str,0,-2);$query_str = "更新 {$tbl_name} {$what_str} {$where_str} LIMIT 1;";$stmt = $this->dbh->prepare($query_str);echo '<pre>'.print_r($stmt, true).'</pre>';foreach($what as $key => $val){if('date_time' === $key) 繼續;$bind = $stmt->bindValue(":{$key}",$val);echo ($bind ? 'true' : 'false')." :{$key}=",$val,'<br/>';}foreach($where as $key => $val){if('date_time' === $key) 繼續;$bind = $stmt->bindValue(":{$key}",$val);echo ($bind ? 'true' : 'false')." :{$key} ",$val,'<br/>';}}別的{返回假;}$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$exec = $stmt->execute();echo 'exec: '.($exec === true ? 'true:' : 'false:').':'.$exec.'<br/>';echo '

                  ';$stmt->debugDumpParams();echo '</pre>';返回 $stmt->errorInfo();}

                  從會話更新/登錄腳本調用:

                  $where = array('id' =>$user['id'],);$what = 數組('twitter_key' =>$oauth_token,'twitter_secret' =>$oauth_token_secret);$update = $db->update('users', $where, $what);

                  類函數和調用者中 echos 和 print_r 的輸出:

                  //print_r($stmt = $this->dbh->prepare($query_str)) 輸出:PDO 語句對象([查詢字符串] =>更新用戶設置`twitter_key` = ':twitter_key', `twitter_secret` = ':twitter_secret' where id = ':id' LIMIT 1;)//bing 參數的輸出和執行返回真:twitter_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX真:twitter_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX真:ID 20執行:真:1//$stmt->debugDumpParams() 輸出:SQL: [111] 更新用戶設置`twitter_key` = ':twitter_key', `twitter_secret` = ':twitter_secret' where id = ':id' LIMIT 1;參數:3密鑰:名稱:[12] :twitter_key參數=-1name=[12] ":twitter_key"is_param=1參數類型=2鍵: 名稱: [15] :twitter_secret參數=-1name=[15] ":twitter_secret"is_param=1參數類型=2鍵:名稱:[3]:id參數=-1名稱=[3] ":id"is_param=1參數類型=2//print_r($stmt->errorInfo()) 輸出:大批([0] =>00000)

                  解決方案

                  我對 PDO 了解不多,但我的感覺是你綁定參數的方式有問題.但是,確定的最簡單方法是查看實際查詢.

                  根據文檔,您應該能夠在 $stmt->queryString 中看到生成的查詢,因為它轉到 SQL.現在無法看到,因為您正在將參數綁定到語句 after 輸出 $stmt.

                  在綁定參數之后(或者甚至在執行查詢之后,我不知道)執行 print_r() .你應該得到真正的查詢字符串,并找到問題的根源.

                  I am having a problem using PHP's PDO object to prepare an update statement and updating the record. I have taken the raw SQL query and ran it in phpMyAdmin with the params replaced by their values that are passed to the function. Which updates the record as intended. However, when ran from the script it does not update. It throws zero errors and it returns an errorInfo() reply of 00000, which to my understanding is PDO's way of saying all is well. I know the PDO object works because it successfully inserts and selects records from the database, including the one I am trying to update. I understand this update function is ugly, I am just learning PDO.

                  Obviously, this is coded in PHP5, using PDO.

                  Class Function:

                  public function update($tbl_name, $where = null, $what = null)
                      {
                          if(is_array($where))
                          {
                              $where_str = 'where ';
                              foreach($where as $key => $val)
                              {
                                  $where_str .= "{$key} = ':{$key}' and ";
                              }
                              $where_str = substr($where_str,0,-5);
                  
                              $what_str = 'set ';
                              foreach($what as $key => $val)
                              {
                                  $what_str .= "`{$key}` = ':{$key}', ";
                              }
                              $what_str = substr($what_str,0,-2);
                  
                              $query_str = "update {$tbl_name} {$what_str} {$where_str} LIMIT 1;";
                              $stmt = $this->dbh->prepare($query_str);
                              echo '<pre>'.print_r($stmt, true).'</pre>';
                              foreach($what as $key => $val)
                              {
                                  if('date_time' === $key) continue;
                                  $bind = $stmt->bindValue(":{$key}",$val);
                                  echo ($bind ? 'true' : 'false')." :{$key}=",$val,'<br/>';
                              }
                              foreach($where as $key => $val)
                              {
                                  if('date_time' === $key) continue;
                                  $bind = $stmt->bindValue(":{$key}",$val);
                                  echo ($bind ? 'true' : 'false')." :{$key} ",$val,'<br/>';
                              }
                          }else{
                              return false;
                          }
                          $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                          $exec = $stmt->execute();
                          echo 'exec: '.($exec === true ? 'true:' : 'false:').':'.$exec.'<br/>';
                  
                          echo '<pre>';
                          $stmt->debugDumpParams();
                          echo '</pre>';
                  
                          return $stmt->errorInfo();
                      }
                  

                  Called from session update/login script:

                  $where = array(
                      'id' => $user['id'],
                      );
                  $what = array(
                      'twitter_key'    => $oauth_token,
                      'twitter_secret' => $oauth_token_secret
                      );
                  
                  $update = $db->update('users', $where, $what);
                  

                  Output from echos and print_r in class function and caller:

                  // print_r($stmt = $this->dbh->prepare($query_str)) output:
                  PDOStatement Object
                  (
                      [queryString] => update users set `twitter_key` = ':twitter_key', `twitter_secret`     = ':twitter_secret' where id = ':id' LIMIT 1;
                  )
                  
                  // output from the bing params and execution returns
                  true :twitter_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
                  true :twitter_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                  true :id 20
                  exec: true:1
                  
                  // $stmt->debugDumpParams() output: 
                  SQL: [111] update users set `twitter_key` = ':twitter_key', `twitter_secret` = ':twitter_secret' where id = ':id' LIMIT 1;
                  Params:  3
                  Key: Name: [12] :twitter_key
                  paramno=-1
                  name=[12] ":twitter_key"
                  is_param=1
                  param_type=2
                  Key: Name: [15] :twitter_secret
                  paramno=-1
                  name=[15] ":twitter_secret"
                  is_param=1
                  param_type=2
                  Key: Name: [3] :id
                  paramno=-1
                  name=[3] ":id"
                  is_param=1
                  param_type=2
                  
                  // print_r($stmt->errorInfo()) output:
                  Array
                  (
                      [0] => 00000
                  )
                  

                  解決方案

                  I don't know much about PDO, but my feeling is there is something wrong with the way you bind the parameters. However, the easiest way to tell for sure is to see the actual query.

                  According to the docs, you should be able to see the generated query as it went to SQL in $stmt->queryString. It's not possible to see right now because you are binding the parameters to the statement after you are outputting $stmt.

                  Do a print_r() after you bind the parameters (or maybe even after execution of the query, I don't know). You should get the real query string, and get to the bottom of the problem.

                  這篇關于PHP PDO 準備好的語句查詢不更新記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='ZXdTM'></small><noframes id='ZXdTM'>

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

                            <tbody id='ZXdTM'></tbody>

                            <tfoot id='ZXdTM'></tfoot>
                          1. 主站蜘蛛池模板: pH污水传感器电极,溶解氧电极传感器-上海科蓝仪表科技有限公司 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | 超声波_清洗机_超声波清洗机专业生产厂家-深圳市好顺超声设备有限公司 | 东莞注册公司-代办营业执照-东莞公司注册代理记账-极刻财税 | 2-羟基泽兰内酯-乙酰蒲公英萜醇-甘草查尔酮A-上海纯优生物科技有限公司 | 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 | 软瓷_柔性面砖_软瓷砖_柔性石材_MCM软瓷厂家_湖北博悦佳软瓷 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 小小作文网_中小学优秀作文范文大全| 压砖机_电动螺旋压力机_粉末成型压力机_郑州华隆机械tel_0371-60121717 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 纸箱抗压机,拉力机,脂肪测定仪,定氮仪-山东德瑞克仪器有限公司 | 天命文免费算命堂_自助算命_自由算命系统_长文周易 | 水厂自动化|污水处理中控系统|水利信息化|智慧水务|智慧农业-山东德艾自动化科技有限公司 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 航空连接器,航空插头,航空插座,航空接插件,航插_深圳鸿万科 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 宁夏活性炭_防护活性炭_催化剂载体炭-宁夏恒辉活性炭有限公司 | 沈阳激光机-沈阳喷码机-沈阳光纤激光打标机-沈阳co2激光打标机 | 深圳网站建设-高端企业网站开发-定制网页设计制作公司 | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 网站建设-网站制作-网站设计-网站开发定制公司-网站SEO优化推广-咏熠软件 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 | 机械加工_绞车配件_立式离心机_减速机-洛阳三永机械厂 | 浙江宝泉阀门有限公司| KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 亿立分板机_曲线_锯片式_走刀_在线式全自动_铣刀_在线V槽分板机-杭州亿协智能装备有限公司 | 橡胶粉碎机_橡胶磨粉机_轮胎粉碎机_轮胎磨粉机-河南鼎聚重工机械制造有限公司 | 济南网站建设|济南建网站|济南网站建设公司【济南腾飞网络】【荐】 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 标策网-专注公司商业知识服务、助力企业发展| 导电银胶_LED封装导电银胶_半导体封装导电胶厂家-上海腾烁 | 螺杆真空泵_耐腐蚀螺杆真空泵_水环真空泵_真空机组_烟台真空泵-烟台斯凯威真空 | 福兰德PVC地板|PVC塑胶地板|PVC运动地板|PVC商用地板-中国弹性地板系统专业解决方案领先供应商! 福建成考网-福建成人高考网 |