简体   繁体   中英

Using DATE ADD with INSERT prepared statement

I'd like to know if its possible and/or sensible to use DATE_ADD with a prepared statement in PHP. I have a number of variables I'm passing to PHP that I want to insert, one is a SQL format datetime and the other is the same datetime but I want to add a number of days to it. The number of days is also held in a variable passed to PHP.. Here's my query so far

$mySql="INSERT INTO delay (delayBookID, delayEED0, delayEDD1, delayDDC, delayUserID, delayCreated) 
VALUE (?,?,DATE_ADD(?,? DAY),?,?,NOW())";

to clarify: here my bind param

$stmt->bind_param('ssssss', $bookID, $edd0, $edd1, $xD4Book, $ddc, $userID); 

Can anyone help??

Thanks in advance

You can use DATE_ADD in an INSERT statement, however, you are missing the key word INTERVAL in DATE_ADD .

It should be DATE_ADD(?, INTERVAL ? DAY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM