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

Java Youtube credentials?

java youtube-api

I'm facing a problem with youtube java credentials,normally it works well and i was able to upload to youtube, but today i' m getting this exception invalid credentials.

java programming get the date from a calendar

java date calendar

i am new to java programming .i do not whether it is possible to connect the external calendar to a java program.i have no previous experience on this.So please help me.