I have this structure:
//Dia atual + i meses
$data_pagamento = "DATE_ADD(CURRENT_TIMESTAMP,INTERVAL ".$i." MONTH)";
$sql = "INSERT INTO pagamento(fk_1, fk_2, fk_3, fk_4, fk_5, preco, data_do_pagamento) VALUES (?,?,?,?,?,?,?)";
$stmt = $db->prepare($sql);
$stmt->execute(array(1, 2, 3, 4, 5, $preco, $data_pagamento));
If I run SELECT DATE_ADD(CURRENT_TIMESTAMP,INTERVAL N MONTH)
the function returns me the current date plus N months, but insert
is not working.
After executing I circled the script var_dump($stmt->debugDumpParams());
Where should appear the string of $data_pagamento
appears:
Key: Position #6: paramno=6 name=[0] "" is_param=1 param_type=2 NULL
Aliases, even if I run directly in the database:
INSERT INTO pagamento(fk_1, fk_2, fk_3, fk_4, fk_5, preco, data_do_pagamento)
VALUES
(1,2,3,4,5,preco,DATE_ADD(CURRENT_TIMESTAMP,INTERVAL N MONTH)
It works as it should!