0
I have the following problem, I have a class called Cliente
with several attributes and a class called DAO_Cliente
that returns a particular account (MySQL
). The problem is when I try to put the values in the attributes of that object, ie when I $id
and the $nome
(only) for example all attributes are with value of the NOME
, as if I set the attribute $telefone1
again all attributes were left with the value of TELEFONE
. I’m using the php4.
Below is the class structure:
Class Cliente
:
<?php
include_once "endereco.php";
class Cliente{
public $id;
public $nome;
public $dataNasc;
public $cpf;
public $identidade;
public $oEndereco;
public $telefone1;
public $telefone2;
public $referencia;
public $status;
public $inscricaoEstadual;
public $celular;
public $email;
public $dataVencimento;
public $dataVisitaTecnica;
public $valorMensalidade;
public $regimeTributario;
public $observacao;
public $qtdeEcf;
public $modelo;
public $possuiNFe;
function __construct() {
$id = 0;
$nome = '';
$dataNasc = 0;
$cpf = '';
$identidade = '';
$oEndereco = new Endereco();
$telefone1 = '';
$telefone2 = '';
$referencia = '';
$status = '';
$inscricaoEstadual = '';
$celular = '';
$email = '';
$dataVencimento = 0;
$dataVisitaTecnica = 0;
$valorMensalidade = 0;
$regimeTributario = '';
$observacao = '';
$qtdeEcf = 0;
$modelo = '';
$possuiNFe = '';
}
}
?>
Class Dao_Cliente
:
<?php
include_once "../conexao.php";
include_once "../model/cliente.php";
class DAO_Cliente{
public function consultar($lcodCli){
$lconexao = conexao::getInstance();
$sql = "SELECT * FROM CLIENTES c WHERE c.codigo_cli = '".$lcodCli."'";
$lconexao->$result = mysql_query($sql) or die("erro de consulta");
if ($consulta = mysql_fetch_array($lconexao->$result)){
$auxCliente = new Cliente();
$auxCliente->$id = $consulta[CODIGO_CLI];
$auxCliente->$nome = $consulta[NOME];
$auxCliente->$dataNasc = $consulta[NASCIMENTO];
$auxCliente->$cpf = $consulta[CPF];
$auxCliente->$identidade = $consulta[IDENTIDADE];
$auxCliente->oEndereco->$logradouro = $consulta[ENDERECO];
$auxCliente->oEndereco->$cep = $consulta[CEP];
$auxCliente->oEndereco->$bairro = $consulta[BAIRRO];
$auxCliente->oEndereco->$cidade = $consulta[CIDADE];
$auxCliente->$telefone1 = $consulta[TELEFONE1];
$auxCliente->$telefone2 = $consulta[TELEFONE2];
$auxCliente->$referencia = $consulta[REFERENCIA];
$auxCliente->$status = $consulta[STATUS];
$auxCliente->$inscricaoEstadual = $consulta[Inscricao_Estadual];
$auxCliente->$celular = $consulta[Celular];
$auxCliente->$email = $consulta[Email];
$auxCliente->$dataVencimento = $consulta[Dvencimento];
$auxCliente->$dataVisitaTecnica = $consulta[DVisitaTecn];
$auxCliente->$valorMensalidade = $consulta[Valor_da_mensalidade];
$auxCliente->$regimeTributario = $consulta[Regime_tributario];
$auxCliente->$observacao = $consulta[Observacao];
$auxCliente->$qtdeEcf = $consulta[QUANT_ECFs_INST];
$auxCliente->$modelo = $consulta[Modelo];
$auxCliente->$possuiNFe = $consulta[NFe];
mysql_free_result($lconexao->$result);
return $auxCliente;
}
return null;
}
?>
And here’s the call where attribute values are duplicated:
if ($auxCliente != null){
echo $auxCliente->$id." - ".$auxCliente->$nome." - ".$auxCliente->$dataNasc." - ".$auxCliente->$cpf." - ".$auxCliente->$identidade." - ".$auxCliente->oEndereco->$logradouro." - ".$auxCliente->oEndereco->$bairro." - ".$auxCliente->oEndereco->$cep." - ".$auxCliente->oEndereco->$cidade." - ".$auxCliente->$telefone1." - ".$auxCliente->$telefone2." - ".$auxCliente->$referencia." - ".$auxCliente->$status." - ".$auxCliente->$inscricaoEstadual." - ".$auxCliente->$celular." - ".$auxCliente->$email." - ".$auxCliente->$dataVencimento." - ".$auxCliente->$dataVisitaTecnica." - ".$auxCliente->$valorMensalidade." - ".$auxCliente->$regimeTributario." - ".$auxCliente->$observacao." - ".$auxCliente->$qtdeEcf." - ".$auxCliente->$modelo." - ".$auxCliente->$possuiNFe;
}
I removed the simple quotes from the database array accesses just to test, but with or without quotation marks the error persists...
– Robson
@Robson Removed the dollar?
– rray
Yes, as you said, only now the attributes of the Client object no longer have any value! In the object Address (within Client) the values of the street attribute are duplicated! Very strange
– Robson
Well, what I realized is that if I take the dollar sign the values of the kind attributes they don’t attribute, they lose the values...
– Robson
Which php vesão you are using?
– rray
Unfortunately the version 4
– Robson
Aaaaa so... I’ll change the answer, she’s facing php5.
– rray
Worked now?
– rray
No need! It’s already solved! Thank you very much rray. The problem was precisely in the dollar sign, both in the $auxCliente->id = $query['CODIGO_CLI']; and in the $auxCliente->id call. As I’m new in php I think I ended up confusing myself and calling always $attribute
– Robson