PDO 使用 PDO::FETCH_PROPS_LATE 和 __construct() 调用?
问题描述
我正在尝试使用 PHP PDO 创建一个 Setting 对象的新实例调用
__construct()
方法并约束 PDO::FETCH_PROPS_LATE.不幸的是,我收到了这个警告(并且绑定不起作用).
如何将列值传递给构造函数方法?
<块引用>警告:pdo.php 中的 Setting::__construct() 缺少参数 1.
注意:未定义变量:pdo.php 中的键.
解决方案 您的构造函数中有一个非默认参数 $key
:
所以,当你这样做时:
错误:
>warning: Missing argument 1 for Setting::__construct() in pdo.php
仅针对参数 $key
抛出,因为它不是默认值.
正确使用fetchAll(PDO::FETCH_CLASS|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?
Warning: Missing argument 1 for Setting::__construct() in pdo.php.
Notice: Undefined variable: key in pdo.php.
You have a non defaulted parameter $key
in your constructor:
So, when you are doing this:
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:
So, in your case:
这篇关于PDO 使用 PDO::FETCH_PROPS_LATE 和 __construct() 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!