It is generally not needed to retrieve column names from the database, you want to work on the values inside the table instead. The column names are just identifiers, so you can link your code and the database, but they don't contain any meaning beyond that.
So for your example, if you want to know what the user with id 1
is allowed to do, you would perform a query like this:
SELECT Allowed_2, Allowed_3 FROM tableName WHERE id = 1
and then use it like this (example in PHP):
// database connection, query, etc.
$row = $result->fetch_assoc();
if ($row['Allowed_2'] === '1') {
echo 'user can do action 2';
}
if ($row['Allowed_3'] === '1') {
echo 'user can do this';
}
If your game grows more complex, with more users, think about introducing roles (eg admin, user, gamemaster, etc). You might have a table called role
, which has an id, a name, and then the different Allowed_X
columns. Then, you can map each user to one or more roles, and manage them that way, which makes it a lot easier to manage users.