0

I'm new to PHP. I've created classes that represent my database tables (I come from a .Net entity framework background). I would like to run my SELECT statement and pass back a User object. All the examples I've found parse the returned data. Is there a way to just do something like this and have it pass back a User object:

$user = new user();

$user = $mysqli->query($query, MYSQLI_STORE_RESULT);

return $user;

or do I have to parse the result first?

Note: all the fields in the user class match the fields in the database I.E. $user->UserName = [user].[UserName]

2

1 Answer 1

1

Try use PDO with "fetchobject":

$statement = $db->query($query);    
$user = $statement->fetchObject('User');

http://www.php.net/manual/en/pdostatement.fetchobject.php

or convert (cast) each "row" of data to User Object (example function)

or try a ORM PHP solution

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.