3
\$\begingroup\$

Are all these steps correct and necessary?

<?php
if (isset($_SESSION['userID'])) {
    $userID = $_SESSION['userID'];
    $stmt = $mysqli->prepare(
       "SELECT usergroup, firstname FROM tbl_users WHERE userID = ? ");
    $stmt->bind_param('i', $userID); 
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($usergroup, $firstname);
    $stmt->fetch();
    $_SESSION['usergroup'] = $usergroup;
    $_SESSION['firstname'] = $firstname;
    $stmt->close();
}   
?>
\$\endgroup\$
1
\$\begingroup\$

More or less, they are... I was using get_result and fetching object more often, but if you want to have the results bound directly to variables, your code is what you need.

By the way, consider using some ORM. I'm using Doctrine2 for my PHP stuff and I'm very satisfied with it

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.