Inserting Data into MySQL Date and Time Columns with mysqli's bind_param
This article explores how to insert data into date or time columns in a MySQL database using PHP's mysqli extension with the bind_param method.
To insert data into a date or time column using mysqli's bind_param, treat it like any other string. Here's an example:
$stmt = $mysqli->prepare('INSERT INTO foo (dt) VALUES (?)'); $dt = '2009-04-30 10:09:00'; $stmt->bind_param('s', $dt); $stmt->execute();
In this example, we prepare a statement for inserting data into the dt column of the foo table. The ? placeholder represents the value to be inserted, which is bound to the $dt variable. The 's' in the bind_param method indicates that the data type is a string, and the value of $dt is passed as an argument. Finally, the statement is executed to insert the data into the database.
The above is the detailed content of How to Insert Dates and Times into MySQL using PHP\'s mysqli bind_param?. For more information, please follow other related articles on the PHP Chinese website!