All this steps are necessary with prepared statement?

All this step are corrects and necessary ?

store_result() and bind_result() togheter ?

<?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();
}   
?>

Answers


Yes.

But a programmer always can write a function to wrap all this code in, and call it in one line

<?php
if (isset($_SESSION['userID'])) {
    $sql = "SELECT usergroup, firstname FROM tbl_users WHERE userID = ?";
    $_SESSION['user'] = $db->getRow($sql, $_SESSION['userID']);
}   

However, I have to admit that to write a function based on mysqli requires extraordinary skill, which renders it practically unreliazable for the most SO users. So, better switch to PDO, as it requires three times less code to handle prepared statement, than mysqli

<?php
if (isset($_SESSION['userID'])) {
    $stm = $pdo->prepare("SELECT usergroup, firstname FROM tbl_users WHERE userID = ?");
    $stm->execute(array(isset($_SESSION['userID']));
    $_SESSION['user'] = $stm->fetch();
}   

Need Your Help

Running Sinatra on port 80

ruby sinatra

I installed Sinatra and it works but it uses port 4567 by default. I want it to run on port 80.

Time fields in Rails app all getting populated with January 1, 2000, 12:00AM

ruby-on-rails ruby-on-rails-3 ruby-1.8.7

I'm using Time to hold the start and end dates within an events controller I'm working on. However my application is neglecting to submit the Time information, in both test and development environm...