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

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

          <bdo id='n2L6t'></bdo><ul id='n2L6t'></ul>

      1. <small id='n2L6t'></small><noframes id='n2L6t'>

        <legend id='n2L6t'><style id='n2L6t'><dir id='n2L6t'><q id='n2L6t'></q></dir></style></legend>
        <tfoot id='n2L6t'></tfoot>

      2. PDO 的 FETCH_INTO $這個(gè)類不起作用

        PDO#39;s FETCH_INTO $this class does not work(PDO 的 FETCH_INTO $這個(gè)類不起作用)
        • <tfoot id='xwSsG'></tfoot>
          <legend id='xwSsG'><style id='xwSsG'><dir id='xwSsG'><q id='xwSsG'></q></dir></style></legend>
            <bdo id='xwSsG'></bdo><ul id='xwSsG'></ul>

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

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

                    <tbody id='xwSsG'></tbody>

                  本文介紹了PDO 的 FETCH_INTO $這個(gè)類不起作用的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我想使用 PDO 的 FETCH_INTO 的構(gòu)造函數(shù)填充類:

                  I want to populate class with constructor using FETCH_INTO of PDO:

                  class user
                  {
                      private $db;
                      private $name;
                  
                      function __construct($id)
                      {
                          $this->db = ...;
                  
                          $q = $this->db->prepare("SELECT name FROM users WHERE id = ?");
                          $q->setFetchMode(PDO::FETCH_INTO, $this);
                          $q->execute(array($id));
                  
                          echo $this->name;
                      }
                  }
                  

                  這不起作用.沒有錯(cuò)誤,只是沒有.腳本沒有錯(cuò)誤,FETCH_ASSOC 工作正常.

                  This does not work. No error, just nothing. Script has no errors, FETCH_ASSOC works fine.

                  FETCH_INTO 有什么問題?

                  推薦答案

                  您的代碼中有兩個(gè)錯(cuò)誤:

                  You have two errors in your code:

                  1) 你忘記了 $q->fetch()

                  1) You forgot $q->fetch()

                   ...
                   $q->execute(array($id));
                   $q->fetch(); // This line is required
                  

                  2) 但即使在添加 $q->fetch() 之后你也會(huì)得到這個(gè):

                  2) But even after adding $q->fetch() you'll get this:

                  致命錯(cuò)誤:無法訪問私有屬性 User::$name in ...

                  Fatal error: Cannot access private property User::$name in ...

                  因此,如您所見,即使在類方法內(nèi)部調(diào)用 PDO,它也無法訪問私有成員.

                  So, as you can see, PDO cannot access private members even if it is called inside class method.

                  這是我的解決方案:

                  ...
                  $q->execute(array($id));
                  $q->setFetchMode(PDO::FETCH_ASSOC);
                  $data = $q->fetch();
                  foreach ($data as $propName => $propValue)
                  {
                      // here you can add check if class property exists if you don't want to
                      // add another properties with public visibility
                      $this->{$propName} = $propValue;
                  }
                  

                  這篇關(guān)于PDO 的 FETCH_INTO $這個(gè)類不起作用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個(gè)服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識(shí)別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個(gè)參數(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的訪問被拒絕)
                    <bdo id='LlXTB'></bdo><ul id='LlXTB'></ul>

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

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

                          <tfoot id='LlXTB'></tfoot>
                          1. 主站蜘蛛池模板: 91精品久久久久久久99 | 91麻豆精品国产91久久久更新资源速度超快 | 免费黄色录像片 | 日本中文字幕在线视频 | 久久午夜视频 | 毛片一区二区 | 午夜精品一区二区三区在线视频 | 国产精品中文字幕一区二区三区 | 亚洲 欧美 日韩 在线 | 午夜激情小视频 | 天天曰夜夜操 | 在线中文字幕av | 国产精品美女久久久久aⅴ国产馆 | 精品一区二区在线视频 | 超碰人人人人 | 日韩色在线 | 成人欧美日韩一区二区三区 | 99热首页| 成人欧美一区二区三区在线播放 | 日本久久一区 | 神马久久春色视频 | 国产一区二区三区在线观看免费 | 免费美女网站 | 国产乱码精品一区二区三区av | 亚洲性视频网站 | 男人的天堂在线视频 | 免费天天干 | 久久99深爱久久99精品 | 日韩无 | 免费成人高清在线视频 | 久久精品av | 99国产精品一区二区三区 | 国产欧美日韩在线 | 国产 欧美 日韩 一区 | 亚洲成人一区二区在线 | www.久久久.com | 91中文字幕在线观看 | 亚洲色图在线观看 | 婷婷色婷婷 | 激情国产视频 | 色一级片 |