<small id='8688t'></small><noframes id='8688t'>

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

    1. <tfoot id='8688t'></tfoot>

      <legend id='8688t'><style id='8688t'><dir id='8688t'><q id='8688t'></q></dir></style></legend>

        PHP PDO 获取对象

        时间:2023-10-05
      1. <legend id='0cqw5'><style id='0cqw5'><dir id='0cqw5'><q id='0cqw5'></q></dir></style></legend>
            <tbody id='0cqw5'></tbody>

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

          • <bdo id='0cqw5'></bdo><ul id='0cqw5'></ul>
            <tfoot id='0cqw5'></tfoot>

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

                  问题描述

                  我试图弄清楚如何从 PDO 获取到我的自定义类,以及一般的 PDO 到对象 API,但我发现缺乏体面的文档令人沮丧.大多数选项仅作为选项记录在案,而示例都使用提取到数组中.
                  那么,有人可以解释一下这些是如何使用的:

                  I am trying to figure out how to fetch from PDO into my custom class, and in general the PDO-to-object API, and am finding the lack of decent documentation frustrating. Most of the options are only documented as an option, while the examples all use fetching into arrays.
                  So, can someone explain how these are used:

                  • PDO::FETCH_OBJ
                  • PDO::FETCH_CLASS
                  • PDO::FETCH_CLASSTYPE
                  • PDO::FETCH_INTO
                  • PDO::FETCH_LAZY
                  • PDOStatement::fetch
                  • PDOStatement::fetchObject
                  • PDOStatement::setFetchMode

                  如果可能的话,我想要一个一般性的解释,说明每个函数/常量是如何用于获取对象的,或者有什么区别,以及我如何获取到我的类中的具体答案,例如进入:

                  If possible, I would like a general explanation how each function/constant is used for fetching objects, or what the differences are, as well as a specific answer to how do I fetch into my class, e.g. into:

                  class MyRow {
                    public $col1, $col2;
                  }
                  

                  推荐答案

                  这是我设法弄清楚的:

                  • PDO::FETCH_OBJ
                    用于获取未命名(匿名")对象的新实例

                  • PDO::FETCH_OBJ
                    Is used to fetch into a new instance of an unnamed ("anonymous") object

                  PDO::FETCH_CLASS
                  用于获取现有类的新实例(列名应与现有属性匹配,或者 __set 应用于接受所有属性).类的构造函数将在属性设置后调用.

                  PDO::FETCH_CLASS
                  Is used to fetch into a new instance of an existing class (the column names should match existing properties, or __set should be used to accept all properties). The constructor of the class will be called after the properties are set.

                  PDO::FETCH_CLASSTYPE
                  FETCH_CLASS(按位或)一起使用,创建实例的类名在第一列,而不是提供给函数.

                  PDO::FETCH_CLASSTYPE
                  Used with FETCH_CLASS (bitwise OR), the name of the class to create an instance of is in the first column, instead of supplied to the function.

                  PDO::FETCH_INTO
                  用于与 FETCH_CLASS 相同类型的类(必须将所有列作为属性名称处理),但更新现有对象而不是创建新对象.

                  PDO::FETCH_INTO
                  Is used with the same type of class as FETCH_CLASS (must handle all columns as property names), but updates an existing object as opposed to creating a new one.

                  PDO::FETCH_LAZY
                  我不知道这是做什么的.

                  PDO::FETCH_LAZY
                  I don't know what this does.

                  • PDOStatement::fetch
                    常规的 get-a-row 命令.我不知道如何将它与 FETCH_CLASSFETCH_INTO 一起使用,因为没有任何方法可以传递类名/实例.

                  • PDOStatement::fetch
                    The regular get-a-row command. I don't know how to use this with FETCH_CLASS or FETCH_INTO since there does not be any way to pass the class name/instance.

                  PDOStatement::fetchObject
                  一种执行 FETCH_CLASSFETCH_INTO 的方法,包括传递构造函数参数.没有参数是 FETCH_OBJ 的简写.

                  PDOStatement::fetchObject
                  A way to do FETCH_CLASS or FETCH_INTO, including passing constructor args. With no args is a shorthand for FETCH_OBJ.

                  PDOStatement::setFetchMode
                  一种设置默认获取模式的方法,以便可以在没有参数的情况下调用 PDOStatment::fetch.

                  PDOStatement::setFetchMode
                  A way to set the default fetch mode, so that PDOStatment::fetch can be called without args.

                  这是我想出的最好的方法.我希望它可以帮助其他人(我需要 fetchObject 方法)

                  That is the best I managed to figure out. I hope it helps someone else (I needed the fetchObject method)

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

                  上一篇:PDO 错误 - PDOException' 带有消息 'SQLSTATE[HY0 下一篇:PHP PDO 缓冲查询问题

                  相关文章

                  最新文章

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

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