简体   繁体   English

PHP:PDO Fetch Class

[英]PHP: PDO Fetch Class

I wanted to know if there was a way to work with a result from a fetch class command without using the foreach loop. 我想知道是否有一种方法可以使用fetch类命令而不使用foreach循环。 I'm trying to create a login function that puts the user info into a class. 我正在尝试创建一个将用户信息放入类中的登录函数。

Is there a way to get get data from a class that holds just one result without loop? 有没有办法从没有循环只保存一个结果的类中获取数据?

$result = $dbquery->fetchALL(PDO::FETCH_CLASS, "userclass");
echo $result->username;

Yes. 是。 Just just use PDOStatement::fetch . 只需使用PDOStatement :: fetch

$dbquery->setFetchMode(PDO::FETCH_CLASS, "userclass");
$result = $dbquery->fetch(PDO::FETCH_CLASS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM