Using Mysqli bind_param with date and time columns?

前端 未结 8 910
清歌不尽
清歌不尽 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:03

    I used the date( ) function and this solved me the problem.

    $stmt = $mysqli->prepare("INSERT INTO FOO (dateColumn) VALUES ?");
    // 6/10/2015 10:30:00
    $datetime = date("Y-m-d H:i:s", mktime(10, 30, 0, 6, 10, 2015));
    $stmt->bind_param("s", $datetime);
    $stmt->execute();
    
    0 讨论(0)
  • 2020-12-08 07:05

    My answer may be slightly off-topic. I had a problem in bind_param when passing date. The date was in (mm/dd/yyyy hh:mm:ss) format. MySQL was not taking it in (yyyy/mm/dd) format (which is the default format of date type in MySQL) in bind_param.

    The following date formatting solved the problem:

    date('Y/m/d', strtotime($date_variable))
    
    0 讨论(0)
提交回复
热议问题