Home > Database > Mysql Tutorial > How to Insert Dates and Times into MySQL using PHP\'s mysqli bind_param?

How to Insert Dates and Times into MySQL using PHP\'s mysqli bind_param?

Barbara Streisand
Release: 2024-11-29 15:05:11
Original
914 people have browsed it

How to Insert Dates and Times into MySQL using PHP's mysqli bind_param?

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();
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template