Inserting into MySQL Date and Time Columns with PHP's mysqli Bind_param
Question:
Can you demonstrate how to insert data into a MySQL date or time column using PHP's mysqli bind_param method?
Answer:
To insert data into a date or time column using bind_param, simply treat it as 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, the query prepares an INSERT statement, where the first (?) represents the placeholder for the date and time value. We bind the value of $dt (a string representation of the date and time) to the placeholder using bind_param('s', $dt), where 's' indicates the data type (string). The execute() method then executes the query.
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!