Home >Database >Mysql Tutorial >How to Insert Date and Time Values into MySQL using mysqli bind_param?

How to Insert Date and Time Values into MySQL using mysqli bind_param?

DDD
DDDOriginal
2024-11-30 17:55:13903browse

How to Insert Date and Time Values into MySQL using mysqli bind_param?

Inserting Date and Time Values with Mysqli bind_param

Inserting data into MySQL date and time columns using PHP mysqli bind_param can be completed seamlessly.

The syntax for inserting date and time values is similar to that used for strings. Here's how you can do it:

$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 create a prepared statement with a placeholder (?) for the date and time value. We then bind the actual value ($dt) to the placeholder using the letter s, which specifies a string data type. Finally, we execute the statement, inserting the date and time data into the foo table's dt column.

The above is the detailed content of How to Insert Date and Time Values into MySQL using 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