try{
$query = "SELECT user_id FROM user WHERE username = '".$username."'";
$result = $dbhandle->query($query,PDO::FETCH_OBJ);
//$stmt->bindParam(":username",$username);
// $result = $stmt->fetchAll(PDO::FETCH_BOTH);
while($row = $result->fetch()){
$id = $row['user_id'];
$_SESSION['user_id'] = $id;
}
}catch(PDOException $e){ echo $e->getMessage();}
You can use this code as sample code
$DBH = new PDO( "connection string goes here" );
$STH - $DBH -> prepare( "SELECT user_id FROM user WHERE username = '".$username."'" );
$STH -> execute();
$result = $STH -> fetch();
echo $result ["user_id"];
$DBH = null;
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.