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

问题描述

我试图创建设置对象调用的新实例 __ construct() 方法与PHP PDO和约束 PDO :: FETCH_PROPS_LATE

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?



Notice: Undefined variable: key in pdo.php.




推荐答案

您有一个非默认参数 $ key

解决方案
You have a non defaulted parameter $key in your constructor:
public function __construct($key, $value = null, $displayable = 1)

所以,当你这样做:

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

错误:警告:设置:: __ construct pdo.php 仅针对参数 $ key ,因为它不是默认值。

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

正确使用 fetchAll(PDO :: FETCH_CLASS | PDO :: FETCH_PROPS_LATE,...
如下:

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>);

p>

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()调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:03