You are not entering user-only data in the database, so I used the command:
print_r($inserir->errorInfo());
And this error appeared:
Array ([0] => HY000 [1] => 1364 [2] => Field 'data_log' does not have a default value)
In the database there is a data_log, ie the creation date of that register, you have no way to ignore this error and save it to the bank? By the way, 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());
}
}