Reputation: 339
I've searched for this but cant find a way to solve this.
$sql = "select count(*) as rule_count from AdminRules where FunctionName = :fn_name and UserLevel in (select user_type from users where user_id = :usid)";
$query = $this->db->prepare($sql);
$parameters = array(':fn_name' => $func_name , ':usid' => $user_id );
if (!$query->execute($parameters)){
return False;
}
echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();
return ($query->fetch()->rule_count >= 1)?True:False;
result of PDO::DEBUG:
[ PDO DEBUG ]: select count(*) as rule_count from AdminRules where FunctionName = 'admin_control' and UserLevel in (select user_type from users where user_id = '2')
result of query is 0:
Array ( [rule_count] => 0 )
however i run the same query in phpmyadmin its (rule_count = 1)
Upvotes: 1
Views: 228
Reputation: 531
It seems the result of your subquery
select user_type
from users
where user_id = :usid
is not a single row, so you should change =
to IN
:
$sql = "select count(*) as rule_count from AdminRules where FunctionName =:fn_name and UserLevel IN (select user_type from users where user_id = :usid)";
Upvotes: 0
Reputation: 339
the user_id is unique so its not, actually i was dumbly watching (phpmyadmin which works on online server) and trying to run my code which is connected to local database.
Upvotes: 1