I am changing the entire system from Mysqli
to PDO
and I am having a problem when trying to insert a date in a field of a record. The record that I try to record is news, which involves a date. The format of the date that I bring with the POST
is of type " 2017-07-26 20:52
" and that date and time is automatically taken by the system. While using mysqli
I had no problems recording records.
$conexion = new Conexion();
$stmt = $conexion -> prepare("INSERT INTO noticias (fecha, titulo, resumen, texto, vigente,
cant_lecturas) VALUES (':fecha', ':titulo', ':sResumen', ':sTexto', ':vigente',
':cant_lecturas')");
$stmt->bindParam(':fecha', $fecha);
$stmt->bindParam(':titulo', $titulo);
$stmt->bindParam(':sResumen', $sResumen);
$stmt->bindParam(':sTexto', $sTexto);
$stmt->bindParam(':vigente', $vigente);
$stmt->bindParam(':cant_lecturas', $cant_lecturas);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$resultado = 1;
} else {
$resultado = null;
}
When executing the insertion process, it throws the following error:
Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format:
1292 Incorrect datetime value: ':fecha' for column 'fecha' at row 1'
What could it be?