<tfoot id='E9WmN'></tfoot>

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

    <legend id='E9WmN'><style id='E9WmN'><dir id='E9WmN'><q id='E9WmN'></q></dir></style></legend>
      1. <small id='E9WmN'></small><noframes id='E9WmN'>

        PDO 使用 PDO::FETCH_PROPS_LATE 和 __construct() 调用?

        时间:2023-10-05
          1. <i id='bboI2'><tr id='bboI2'><dt id='bboI2'><q id='bboI2'><span id='bboI2'><b id='bboI2'><form id='bboI2'><ins id='bboI2'></ins><ul id='bboI2'></ul><sub id='bboI2'></sub></form><legend id='bboI2'></legend><bdo id='bboI2'><pre id='bboI2'><center id='bboI2'></center></pre></bdo></b><th id='bboI2'></th></span></q></dt></tr></i><div id='bboI2'><tfoot id='bboI2'></tfoot><dl id='bboI2'><fieldset id='bboI2'></fieldset></dl></div>
              <bdo id='bboI2'></bdo><ul id='bboI2'></ul>
                <tbody id='bboI2'></tbody>
                1. <tfoot id='bboI2'></tfoot>

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

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

                2. 本文介绍了PDO 使用 PDO::FETCH_PROPS_LATE 和 __construct() 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 PHP PDO 创建一个 Setting 对象的新实例调用 __construct() 方法并约束 PDO::FETCH_PROPS_LATE.不幸的是,我收到了这个警告(并且绑定不起作用).

                  如何将列值传递给构造函数方法?

                  <块引用>

                  警告:pdo.php 中的 Setting::__construct() 缺少参数 1.

                  注意:未定义变量:pdo.php 中的键.

                  类设置{受保护的 $key, $value, $displayable;公共函数 __construct($key, $value = null, $displayable = 1){$this->key = $key;$this->value = $value;$this->displayable = $displayable >0;}}while($mashup = current($mashup)){$stmt = $dbh->prepare('SELECT `key`, value, displayable从设置 WHERE mashup_id = :id');$stmt->bindParam(':id', $mashup->id, PDO::PARAM_INT);$stmt->execute();$settings = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'环境');}$stmt->closeCursor();

                  解决方案

                  您的构造函数中有一个非默认参数 $key:

                  public function __construct($key, $value = null, $displayable = 1)

                  所以,当你这样做时:

                  $settings = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'Setting');

                  错误:warning: Missing argument 1 for Setting::__construct() in pdo.php 仅针对参数 $key 抛出,因为它不是默认值.>

                  正确使用fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,...是这样的:

                  $variable = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'班级名称',<构造函数中使用的参数名称数组(按顺序)>);

                  所以,就你而言:

                  $variable = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'环境',array('key', 'value', 'displayable');

                  I'm trying to create a new instance of Setting object calling __construct() method with PHP PDO and constrain PDO::FETCH_PROPS_LATE. Unfortunatly i'm getting this warning (and binding doesn't work).

                  How can pass column values to the constructor method?

                  Warning: Missing argument 1 for Setting::__construct() in pdo.php.

                  Notice: Undefined variable: key in pdo.php.

                  class Setting
                  {
                  
                      protected $key, $value, $displayable;
                  
                      public function __construct($key, $value = null, $displayable = 1)
                      {
                          $this->key         = $key;
                          $this->value       = $value;
                          $this->displayable = $displayable > 0;
                      }
                  
                  }
                  
                  while($mashup = current($mashups))
                  {
                      $stmt = $dbh->prepare('SELECT `key`, value, displayable
                          FROM setting WHERE mashup_id = :id');
                  
                      $stmt->bindParam(':id', $mashup->id, PDO::PARAM_INT);
                      $stmt->execute();
                  
                      $settings = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,
                         'Setting');
                  }
                  
                  $stmt->closeCursor();
                  

                  解决方案

                  You have a non defaulted parameter $key in your constructor:

                  public function __construct($key, $value = null, $displayable = 1)
                  

                  So, when you are doing this:

                  $settings = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'Setting');
                  

                  Error: warning: Missing argument 1 for Setting::__construct() in pdo.php is thrown only for parameter $key because it is not defaulted.

                  The correct use of fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,... is like this:

                  $variable = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,
                                             'classname', 
                                              <array of parameter names(in order) used in constructor>);
                  

                  So, in your case:

                  $variable = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,
                                              'Setting', 
                                               array('key', 'value', 'displayable');
                  

                  这篇关于PDO 使用 PDO::FETCH_PROPS_LATE 和 __construct() 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP - PDO 引用是否安全从 SQL 注入? 下一篇:获取带有绑定参数的 PDO 查询字符串而不执行它

                  相关文章

                  最新文章

                    <small id='2xHs3'></small><noframes id='2xHs3'>

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

                    1. <legend id='2xHs3'><style id='2xHs3'><dir id='2xHs3'><q id='2xHs3'></q></dir></style></legend><tfoot id='2xHs3'></tfoot>