I made this example for you to understand how the query is done in the bank on my system.
$sql = "SELECT * FROM tabela";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["campo"];
}
}
My problem is the following, I'm getting the result of the query and if it is in an object, until then, the problem is when null values arrive, if I have a 'NULL' string or a null field the result is the same, how can I differentiate null from a 'NULL' string?
Values in the object:
'nChegada' => 'NULL',
'nExpedido' => 'NULL',
One is null and the other is a string 'NULL'.
UPDATE
Value of n_chegada and n_estate are null and of n_query is a string
Code:
publicfunctiongetDadoById($id){$stmt=$this->conexao->getQuery("select * from " . $this->getTabela() . " WHERE 'id' = " . $id);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$cla = null;
if (count($results) > 0) {
$atributos = $this->getAtributos();
$classe = 'model\dominio\' . ucfirst($this->getTabela());
$cla = new $classe();
foreach ($atributos as $atributo) {
$metodo = 'set' . ucfirst($atributo);
if(is_null($results[0][$this->atributoToDb($atributo)])){
$cla->$metodo(NULL);
}else{
$cla->$metodo($results[0][$this->atributoToDb($atributo)]);
}
}
}
return $cla;
}
I tried with the example of Roberto de Campos, but the result was the same:
model\dominio\Funcionario::__set_state(array(
'id' => '1',
'pis' => '12345678901',
'numeroCarteira' => '12345',
'serie' => '1234',
'nome' => 'Trabalhador Padrão',
'mae' => 'Mãe do Trabalhador Padrão',
'pai' => 'Pai do Trabalhador Padrão',
'dataNascimento' => '10/10/1988',
'sexo' => '1',
'estadoCivil' => '1',
'naturalidade' => '2680',
'rg' => '1234567890',
'cpf' => '12345678901',
'cnh' => '12345678901',
'tituloEleitoral' => '123456789012',
'secao' => '1234',
'zona' => '123',
'localEmissao' => '2680',
'nacionalidade' => '7',
'nChegada' => 'NULL',
'nExpedido' => 'NULL',
'nEstado' => 'NULL',
'observacao' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.',
'email' => '[email protected]',
'senha' => '123',
'dataEmissao' => '2017-10-23 13:12:42',
))