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

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

Susan Sarandon
Release: 2024-11-27 16:27:15
Original
832 people have browsed it

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

Using MySqli bind_param to Insert Date and Time Data

Inserting date and time values into MySQL columns using PHP mysqli and bind_param involves treating them like any other string. Here's how to do it:

  1. Prepare the Statement:
$stmt = $mysqli->prepare('insert into foo (dt) values (?)');
Copy after login
  1. Bind the Date or Time Value:

Use the 's' format specifier to bind a string. For example, for a date-time value of '2009-04-30 10:09:00':

$dt = '2009-04-30 10:09:00';
$stmt->bind_param('s', $dt);
Copy after login
  1. Execute the Statement:
$stmt->execute();
Copy after login

By following this approach, you can insert date and time values into MySQL columns efficiently using mysqli and bind_param.

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