I want to store a string variable as a date in a DATE type column using this code.
$affectedRows = $pdo->exec("UPDATE `$table_final` SET `Date_B` = $Date_Courant, `Id_SB` = $NoStation");
where $Date_Courant
is defined as the string: 2022-07-01
I get this error message:
( ! ) Fatal error: in C:\Users\Jean Claude\Documents\ADNA06\Développements\FormationWamp\LoadData_Infile_Pics_Temp_Jours_Stations.php on line 116
( ! ) PDOException: in C:\Users\Jean Claude\Documents\ADNA06\Développements\FormationWamp\LoadData_Infile_Pics_Temp_Jours_Stations.php on line 116
Call Stack
1 0.0072 361904 {main}( ) ...\LoadData_Infile_Pics_Temp_Jours_Stations.php:0
2 0.1586 429024 exec( $query = 'UPDATE `picbruit` SET `Date_B` = (DATE) 2022-07-01, `Id_SB` = 1' ) ...\LoadData_Infile_Pics_Temp_Jours_Stations.php:116
I tried with the CAST instruction as follows: same error message.
$affectedRows = $pdo->exec("UPDATE `$table_final` SET `Date_B` = (DATE) $Date_Courant, `Id_SB` = $NoStation");
What is the proper way of doing this?