Hi,
I'm working on a small project and I like the Query to check something for me. However for that I need to select something which is also needed in the WHERE clause.
// Prepare Query
$sql = "SELECT ? FROM permissions WHERE (req = ? AND single_delete = '1')";
$stmt = $db->prepare($sql);
// Bind Parameters and execute.
$stmt->bind_param("si", $action, $user['permissions']);
$stmt->execute();
// Store result and make it a variable.
$stmt->store_result();
$permissioncount = $stmt->num_rows;
return $permissioncount;
Like this it's working. It returns the correct count. However as soon as I change single_delete
to the variable $action
, it will return 0
. The variable $action
contains single_delete
. My Question is, why isn't it possible or what am I doing wrong?
The code
// Prepare Query
$sql = "SELECT ? FROM permissions WHERE (req = ? AND ? = '1')";
$stmt = $db->prepare($sql);
// Bind Parameters and execute.
$stmt->bind_param("sis", $action, $user['permissions'], $action);
$stmt->execute();
// Store result and make it a variable.
$stmt->store_result();
$permissioncount = $stmt->num_rows;
return $permissioncount;