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?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-08 17:56:11982browse

How to Insert Dates and Times into MySQL Using PHP's mysqli_bind_param?

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!

Statement:
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