I have a select statement which will only ever return one row.
$sql = "select user_type, username, permanent_id, password, suspended from users where username = :username";
$statement = $databaseConnection->prepare($sql);
$statement->bindParam(":username", $username, PDO::PARAM_STR);
$statement->execute();
I'm looking to pick out the value from each column and assign to the following variables:
$isAdmin = $statement->fetchColumn(0) == "admin" ? true : false;
$storedUsername = $statement->fetchColumn(1);
$storedPermanentID = $statement->fetchColumn(2);
$storedPassword = $statement->fetchColumn(3);
$isSuspended = $statement->fetchColumn(4) == 1 ? true : false;
The fact that fetchColumn accepts an integer of the zero-indexed columns made me think I could pick out the value from each column from the same row. This appears not to be the case, because I'm getting blanks.
I've ensured that the select statement works in phpMyAdmin.
I used to make individual calls to the database to get the value for each variable, but I'm trying to reduce code replication.
Apologies if this is a noob question, there are holes in my knowledge perhaps where they shouldn't be.
Thank you for your help :)