I wanted to know if there was a way to work with a result from a fetch class command without using the foreach loop. 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 .
$dbquery->setFetchMode(PDO::FETCH_CLASS, "userclass");
$result = $dbquery->fetch(PDO::FETCH_CLASS);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.