I'd like to know what is more efficient, make just one query and store the result in an array and then check this array using the function in_array from PHP or make a MySQL query every time I need to check the value?
For example: I created this function to store the query in a array, so this query will be made just one time.
private function carregaPermissoes(){
$query = mysql_query("SELECT permissao_nome FROM sisgrupopermissoes WHERE id_grupo = ".$this->getGid().";");
if (mysql_num_rows($query) > 0){
$array_permissoes = array();
while ($row = mysql_fetch_array($query)){
array_push($array_permissoes, $row["permissao_nome"]);
}
return $array_permissoes;
}
}
Then every time I need to check it I just use this function:
public function checkPermissao($permissao){
$this->setPermissao($permissao);
if (in_array($this->getPermissao(), $this->getGrupoPermissao())){
return true;
}else{
return false;
}
}
Is it a good way to do it? Or is better make a query every time I need to check it?