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

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

      1. <legend id='rkMfZ'><style id='rkMfZ'><dir id='rkMfZ'><q id='rkMfZ'></q></dir></style></legend>
      2. PDO PHP 获取类

        时间:2023-09-21

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

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

                  <tfoot id='ZRtgW'></tfoot><legend id='ZRtgW'><style id='ZRtgW'><dir id='ZRtgW'><q id='ZRtgW'></q></dir></style></legend>
                    <tbody id='ZRtgW'></tbody>
                • <i id='ZRtgW'><tr id='ZRtgW'><dt id='ZRtgW'><q id='ZRtgW'><span id='ZRtgW'><b id='ZRtgW'><form id='ZRtgW'><ins id='ZRtgW'></ins><ul id='ZRtgW'></ul><sub id='ZRtgW'></sub></form><legend id='ZRtgW'></legend><bdo id='ZRtgW'><pre id='ZRtgW'><center id='ZRtgW'></center></pre></bdo></b><th id='ZRtgW'></th></span></q></dt></tr></i><div id='ZRtgW'><tfoot id='ZRtgW'></tfoot><dl id='ZRtgW'><fieldset id='ZRtgW'></fieldset></dl></div>
                • 本文介绍了PDO PHP 获取类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在 php 中学习 pdo,以便使数据库访问更容易和更高效.我读过的一个关于 fetch _class 的解释是你的对象的属性是在调用构造函数之前设置的.这是什么意思?任何方向都非常感谢.

                  I am learning pdo in php , so as to make database access easier and more efficient .One explanation i have read for fetch _class is that The properties of your object are set BEFORE the constructor is called.What does this mean? Any direction is greatly appreciated.

                  推荐答案

                  这意味着在使用 PDO 将结果返回到自定义对象时,需要设置查询结果键对应的成员变量.

                  This means that when using PDO to return a result into a custom object, you are required to set out the member variables which correspond to the query result keys.

                  例如:

                  class User
                  {
                      //Predefine Here
                      public $id;
                      public $username;
                      public $password;
                      public $email;
                      public $hash;
                  
                      public function profileLink()
                      {
                           return sprintf('<a href="/profile/%s">%s</a>',$this->id,$this->username);
                      }
                  }
                  
                  $result = $sth->fetchAll(PDO::FETCH_CLASS, "User");
                  foreach($result as $user)
                  {
                      echo $user->profileLink();
                  }
                  

                  通过这种方式,PDO 可以将变量设置到其内部范围之外的对象.

                  This way PDO can set the variables to the object outside of its internal scope.

                  如果你的用户类是这样的:

                  if you user class was like so:

                  class User
                  {
                  }
                  

                  然后 PDO 将无法从范围之外设置值,因为没有定义属性.

                  then PDO Would not be able to set the values from outside the scope, as there are no properties defined.

                  这篇关于PDO PHP 获取类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 pdo 的准备好的语句用于 order by 和 limit 子 下一篇:什么是 PDO &amp;我为什么要使用它?

                  相关文章

                  最新文章

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

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

                      <legend id='LJ01d'><style id='LJ01d'><dir id='LJ01d'><q id='LJ01d'></q></dir></style></legend>