简体   繁体   中英

Date_ADD function works in MySQL but not in php

I have searched everywhere but I cant find anyone else experiencing this

When I run this in MySQL (via phpmyadmin) it works fine

 UPDATE users SET timetoken=DATE_ADD((now()), INTERVAL 1 HOUR) WHERE username='usman'

And then this is my php

 mysqli_query($con,"UPDATE users SET timetoken=DATE_ADD((now()), INTERVAL 5 HOUR) WHERE username='usman'");

It will update the field, but oddly enough it changes the date to the current time and does not add the hours

Can anyone help?

Try:

// Set $q to sql query
$q = "UPDATE users SET timetoken = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 5 HOUR) WHERE username = 'usman'";

// Execute query
mysqli_query($con, $q);

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