1
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 execute SELECT DATE_ADD(CURRENT_TIMESTAMP,INTERVAL N MONTH)
the function returns me the current date plus N months, but no insert
is not working.
After the run I ran the script var_dump($stmt->debugDumpParams());
Where the string of $data_pagamento
appears:
Key: Position #6: paramno=6 name=[0] "" is_param=1 param_type=2 NULL
By the way, even if I run right into the bank:
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!
what is the type of the payment data_do_field, this date, datetime? apparently it is all right Marco
– kurole
You are trying to put a string in the field. It makes no sense to try to insert "DATE_ADD(CURRENT_TIMESTAMP,INTERVAL ".$i." MONTH)"; in the field. Either you do this in SQL, or you calculate in PHP.
– Bacco