0
You are not only entering user data in the database, so I used the command:
print_r($inserir->errorInfo());
And this mistake appeared:
Array ( [0] => HY000 [1] => 1364 [2] => Field 'data_log' doesn’t have the default value )
In the bank there is the data_log, ie the creation date of that registration, there is no way to ignore this error and save in the bank? In fact, save but not create future problems...
public function inserir($tabela, $dados){
$pegarCampos = array_keys($dados);
$contarCampos = count($pegarCampos);
$pegarValores = array_values($dados);
$contarValores = count($pegarValores);
$sql = "INSERT INTO $tabela (";
if($contarCampos == $contarValores){
foreach($pegarCampos as $campo){
$sql .= $campo.', ';
}
$sql = substr_replace($sql, ")", -2, 1);
$sql .= "VALUES (";
for($i = 0; $i < $contarValores; $i++){
$sql .= "?, ";
$i;
}
$sql = substr_replace($sql, ")", -2, 1);
}else{
return false;
}
try{
$inserir = self::conn()->prepare($sql);
if($inserir->execute($pegarValores)){
return true;
}else{
return false;
}
}catch(PDOException $e){
print_r($inserir->errorInfo());
}
}