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]

asked Aug 7, 2012 at 18:35
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

answered Aug 7, 2012 at 18:38

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.