本文介绍了PHP PDO:获取样式 FETCH_CLASS 和 FETCH_INTO 是否获取到私有对象属性中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
限时送ChatGPT账号..
很短的问题,这是一个例子:
Pretty short question, here is an example:
$prepared = $this->pdo->prepare("SELECT * FROM Users WHERE ID = :ID");
$statement = $prepared->execute(array(":ID" => $User_ID))
$result = $statement->fetchAll(PDO::FETCH_CLASS, "User");
//OR
$User = new User();
$result = $statement->fetch(PDO::FETCH_INTO, $User);
(从头开始写,可能包含语法错误)
(written from top of the head, could contain syntax errors)
这两个是否直接获取到所述对象的私有属性?我读到它也绕过了 __construct 函数,那么它也会绕过私有状态吗?
Do those two directly fetch into the private properties of said objects?
I read it also circumvents the __construct function, so will it circumvent private status too?
推荐答案
非常简短的回答:是的.
Very short answer: Yes it will.
class Foo
{
private $id;
public function echoID()
{
echo $this->id;
}
}
$result = $statement->fetchAll(PDO::FETCH_CLASS, "Foo");
$result[0]->echoID(); // your ID
<小时>
旁白:
这会导致语法错误$statement->fetchAll(PDO::FETCH_INTO, $User);.您不能将 FETCH_INTO 与 fetchAll 方法一起使用.
This will cause syntax errors $statement->fetchAll(PDO::FETCH_INTO, $User);. You can't use FETCH_INTO with the fetchAll method.
这篇关于PHP PDO:获取样式 FETCH_CLASS 和 FETCH_INTO 是否获取到私有对象属性中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)