<legend id='0TImN'><style id='0TImN'><dir id='0TImN'><q id='0TImN'></q></dir></style></legend>

  • <tfoot id='0TImN'></tfoot>

        <small id='0TImN'></small><noframes id='0TImN'>

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

        PDO - FETCH_CLASS - 将结果作为参数传递给构造函数

        时间:2023-09-20

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

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

                  <bdo id='nkMaR'></bdo><ul id='nkMaR'></ul>
                  本文介绍了PDO - FETCH_CLASS - 将结果作为参数传递给构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  有什么办法可以将 PDO 的结果作为构造函数的参数传递?假设我有以下课程:

                  Is there any way, to pass results of PDO as parameters of the constructor? Let's say, I have the following class:

                  class Test
                  {
                      private $value1;
                      private $value2;
                      function __construct($val1, $val2)
                      {
                          $this->value1 = $val1; $this->value2 = $val2;
                      }
                  }
                  

                  然后,通过 PDO 驱动程序,我从数据库中选择一些数据,让我们说:

                  Then, via PDO driver I select some data from DB, let's say:

                  SELECT price, quantity FROM stock
                  
                  $results = $query->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, "Test");
                  

                  现在,PDO 将这些值直接传递给类字段,并绕过构造函数.

                  Right now, PDO passess these values directly to the class fields, and bypassing the constructor.

                  也许我遗漏了一些东西,但我想将查询的结果传递给构造函数.构造函数不能依赖于查询,我希望即使不使用 PDO 也能实例化这个类.

                  Maybe I am missing something, but I want to pass results from the query to the constructor. Constructor cannot be query-dependent, I want to be able to instantiate this class even without using PDO.

                  推荐答案

                  [我编辑了这个答案,因为我之前的答案不再准确.]

                  [I edited this answer as my previous answer is not accurate anymore.]

                  FETCH_CLASS 确实会获取私有属性.请参考这个答案.

                  FETCH_CLASS does fetch into private properties. Please refer to this answer.

                  这篇关于PDO - FETCH_CLASS - 将结果作为参数传递给构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP PDO 连接到具有集成安全性的 SQL Server? 下一篇:如何使用pdo从sql中删除数据?

                  相关文章

                  最新文章

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

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

                    1. <tfoot id='UvDPh'></tfoot>
                        <bdo id='UvDPh'></bdo><ul id='UvDPh'></ul>

                    2. <legend id='UvDPh'><style id='UvDPh'><dir id='UvDPh'><q id='UvDPh'></q></dir></style></legend>