Are all these steps correct and necessary?

if (isset($_SESSION['userID'])) {
    $userID = $_SESSION['userID'];
    $stmt = $mysqli->prepare(
       "SELECT usergroup, firstname FROM tbl_users WHERE userID = ? ");
    $stmt->bind_param('i', $userID); 
    $stmt->bind_result($usergroup, $firstname);
    $_SESSION['usergroup'] = $usergroup;
    $_SESSION['firstname'] = $firstname;

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


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.