Field 'data_log' does not have a default value - Does not enter data in the database

1

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());
    }
}
    
asked by anonymous 16.10.2017 / 15:23

1 answer

2

This happens because of the mysql-strict that is configured on your server, so the data_log field can not be empty when you are inserting the data.

You can disable mysql strict in this way:

set @@global.sql_mode='';

Or in your query, insert some value into data_log

    
16.10.2017 / 16:40