Using Mysqli bind_param with date and time columns?

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

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

8条回答
  •  Happy的楠姐
    2020-12-08 06:55

    first set the date & time using date() function-

    $date=date("d/m/y");
    $time=date("h:i:sa");
    

    then pass it into the prepared statement, just like any other string variable-

    $stmt = $mysqli->prepare("INSERT INTO FOO (dateColumn, timeColumn) VALUES (?,?)");
    $stmt->bind_param("ss", $date , $time);
    $stmt->execute();
    

提交回复
热议问题