Using Mysqli bind_param with date and time columns?

前端 未结 8 911
清歌不尽
清歌不尽 2020-12-08 06:14

How do you insert data into a MySQL date or time column using PHP mysqli and bind_param?

8条回答
  •  时光取名叫无心
    2020-12-08 07:01

    Timestamps in PHP are integers (the number of seconds from the UNIX epoch). An alternative to the above is to use an integer type date/time parameter, and the MySQL functions FROM_UNIXTIME and UNIX_TIMESTAMP

    $stmt = $mysqli->prepare("INSERT INTO FOO (dateColumn) VALUES (FROM_UNIXTIME(?))");
    $stmt->bind_param("i", $your_date_parameter);
    $stmt->execute();
    

提交回复
热议问题