0
I have the following code below:
public function listarClientesBuscadosDoForm()
{   
    try
    {                       
        $c = new Conexao();
        $db = $c->conectar();
        $query = "SELECT a.cod, a.razao_social, a.cnpj, a.inscricao_estadual, a.servico, 
        b.tributacao, c.atividade_economica FROM clientes AS a 
        INNER JOIN tributacoes AS b ON a.id_tributacao = b.id
        INNER JOIN atividade_economica AS c ON a.id_atividade_economica = c.id
        WHERE a.razao_social LIKE :razao_social AND a.cnpj LIKE :cnpj
        AND a.inscricao_estadual LIKE :inscricao_estadual AND a.id_tributacao
        LIKE :id_tributacao AND a.id_atividade_economica LIKE :id_atividade_economica";
        $stmt = $db->prepare($query);                   
        $stmt->bindValue(':razao_social',"%". $this->razao_social ."%");
        $stmt->bindValue(':id_tributacao ',"%". $this->tributacao ."%");                                                    
        $stmt->bindValue(':cnpj',"%". $this->cnpj ."%");
        $stmt->bindValue(':inscricao_estadual',"%". $this->inscricao_estadual ."%");
        $stmt->bindValue(':id_atividade_economica',"%". $this->id_atividade_economica ."%");                    
        $stmt->execute();
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);    
        echo json_encode($result);
   } catch(PDOException $e) {
                    echo "Erro: ".$e->getCode()." Mensagem: ".$e->getMessage();             
   }
}
Would you recommend a correct way to perform this type of consultation ? This data that is passed to the query is coming from a query form (HTML) and they can come empty as well (correct is if it comes empty, bring all the data). The problem is that I use 3 tables and Inner Join in this query.
Below is the description of the 3 tables:
tributary
Form (HTML):
Would you have any idea of the correct way for me to perform this query or build this code ?



