2

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

1 Answer 1

3

Yes. Just just use PDOStatement::fetch.

$dbquery->setFetchMode(PDO::FETCH_CLASS, "userclass");
$result = $dbquery->fetch(PDO::FETCH_CLASS);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.