Field 'data_log' doesn’t have a default value - Does not insert data into the database

Asked

Viewed 853 times

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());
    }
}

1 answer

1


This happens because mysql-Strict is configured on your server, so the data_log field cannot be empty when you are entering the data.

You can disable mysql Strict this way:

set @@global.sql_mode='';

Or in your query, insert some value in data_log

Browser other questions tagged

You are not signed in. Login or sign up in order to post.