Ir para conteúdo
Fórum Script Brasil
  • 0

Dúvida Class


jrbiasi

Pergunta

Boa tarde tudo beleza ? espero que sim 

Estou com um problema de na minha class que me retorna assim: Using $this when not in object context 

public function __construct($id = null) { 
$this->db = DB::getInstance(); 
if($id != null) { 
$this->load($id); 
} 
} 

public static function InscricoesExists($id) { 
// BEM AQUI TA DANDO O ERRO NO $this->db-executeSql 
$this->db->executeSql("SELECT `id` FROM `custom_inscricoes` WHERE `id` = '{$id}'"); 
if($this->db->getNumRows() > 0) { 
return true; 
} else { 
return false; 
} 
} 

Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

  • 0

Olá!

É na linha do getNumRows()?

Se for, creio q você deve guardar o resultado da execução da query em alguma variável:

$result = $this->db->executeSql...

Se não for, mostre-nos o método getNumRows()

 

Link para o comentário
Compartilhar em outros sites

  • 0

Galera, eu agradeço de mais a ajuda de vocês, mas eu já consegui arruma o suposto erro (obs: falha minha)

Vou deixar a class aqui para vocês darem uma olhada

 

<?php 
class Inscricoes{
    private $id;
    private $fk_custom_eventos;
    private $fk_custom_status;
    private $nome;
    private $email;
    private $tel_telefone;
    private $num_cpf_cnpj;
    private $created;
    private $updated;
    
    public function __construct($id = null) {
        $this->db = DB::getInstance();
        if($id != null) {
            $this->load($id);
        }
    }
            
    public function InscricoesExists($id) {
        $this->db->executeSql("SELECT `id` FROM `custom_inscricoes` WHERE `id` = '{$id}'");
        $result = $this->db->fetchAll();
        if(count($result) > 0) {
            return true;
        } else {
            return false;
        }
    }
    
    public function load($id) {
        if(!self::InscricoesExists($id)) {
            return false;
        }
                
        $this->db->executeSql("SELECT `id`,`fk_custom_eventos`,`fk_custom_status`,`nome`,`email`,`tel_telefone`,`num_cpf_cnpj`,`created`,`updated` FROM `custom_inscricoes` WHERE `id`='{$id}'");
        $row = $this->db->fetch();
        $this->id = $row['id'];
        $this->fk_custom_eventos = $row['fk_custom_eventos'];
        $this->fk_custom_status = $row['fk_custom_status'];
        $this->nome = $row['nome'];
        $this->email = $row['email'];
        $this->tel_telefone = $row['tel_telefone'];
        $this->num_cpf_cnpj = $row['num_cpf_cnpj'];
        $this->created = $row['created'];
        $this->updated = $row['updated'];
    }

    public function save() {
        if(self::InscricoesExists($this->id)) {
            $this->db->executeSql("UPDATE custom_inscricoes SET fk_custom_eventos = '{$this->fk_custom_eventos}', fk_custom_status = '{$this->fk_custom_status}', nome = '{$this->nome}', email = '{$this->email}', tel_telefone = '{$this->tel_telefone}', num_cpf_cnpj = '{$this->num_cpf_cnpj}', updated = '{$this->updated}' WHERE id = '{$this->id}'");    
        } else {
            $this->db->executeSql("INSERT INTO `custom_inscricoes` (`id`,`fk_custom_eventos`,`fk_custom_status`,`nome`,`email`,`tel_telefone`,`num_cpf_cnpj`,`created`) VALUES (NULL, '{$this->fk_custom_eventos}','{$this->fk_custom_status}','{$this->nome}','{$this->email}','{$this->tel_telefone}','{$this->num_cpf_cnpj}','{$this->created}')");
            $this->db->executeSql("SELECT MAX(id) as id FROM custom_inscricoes");
            $row = $this->db->fetch();
            $this->load($row['id']);
        }
    }
    
    public function getId(){
        return $this->id;
    }    
    public function getFkCustomEventos(){
        return $this->fk_custom_eventos;
    }    
    public function getFkCustomStatus(){
        return $this->fk_custom_status;
    }    
    public function getNome(){
        return $this->nome;
    }    
    public function getEmail(){
        return $this->email;
    }    
    public function getTelTelefone(){
        return $this->tel_telefone;
    }    
    public function getNumCpfCnpj(){
        return $this->num_cpf_cnpj;
    }
    public function getCreated() {
        return $this->created;
    }
    public function getUpdated() {
        return $this->updated;
    }
    
    public function setId($id){
        $this->id = $id;
    }    
    public function setFkCustomEventos($fk_custom_eventos){
        $this->fk_custom_eventos = $fk_custom_eventos;
    }    
    public function setFkCustomStatus($fk_custom_status){
        $this->fk_custom_status = $fk_custom_status;
    }    
    public function setNome($nome){
        $this->nome = $nome;
    }    
    public function setEmail($email){
        $this->email = $email;
    }    
    public function setTelTelefone($tel_telefone){
        $this->tel_telefone = $tel_telefone;
    }    
    public function setNumCpfCnpj($num_cpf_cnpj){
        $this->num_cpf_cnpj = $num_cpf_cnpj;
    }
    public function setCreated($created) {
        $this->created = $created;
    }
    public function setUpdated($updated) {
        $this->updated = $updated;
    }
    
}

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,7k
×
×
  • Criar Novo...