1

When using prepared statements in MySQLi, and inserting a date into a MySQL database, what parameter should i then use?

Example code:

<?php
$db = new mysqli('localhost', 'root', '', 'database');
$date = date("Y-m-d")
$stmt = $db->prepare("INSERT INTO table (date) VALUE (?)");
$stmt->bind_param("WHAT PARAMETER TO USE?", $date); // <--- What parameter?
$stnt->execute();
$stmt->close();
?>

Summary:

When inserting into MySQL database with MySQLI (Row type is 'date'), what parameter is the correct to use with the bind_param when using prepared statements? Is it just 's' for string, or...?

If i made some bad code above, i would be happy to know. I'm new to MySQLi, and it would be nice to know what i made wrong.

Thanks in advance.

2 Answers2

0

You can use "s" this could be used for date, datetime. Its treated as just any other string.

$stmt->bind_param('s', $date);
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
-1

What's 'date' type? Is it an integer or a string?

If it's a string, use s.

If it's a integer, which only have numbers, use i.

But, in this case date('Y-m-d'); will output as: 2014-03-16, you better use string. Because it have '-'.

Reinaldy
  • 205
  • 2
  • 5
  • 14