PDO::PARAM 日期?
是否存在一些可用于日期或时间戳的 PDO::PARAM_???
?
Does some PDO::PARAM_???
exist which can be used for dates or timestamps?
示例代码:
$sql = "UPDATE my_table SET current_date = :date WHERE id = 43";
$statement = $pdo->prepare ($sql);
$statement->bindValue (":date", strtotime (date ("Y-m-d H:i:s")), PDO::PARAM_STR);
$statement->execute ();
推荐答案
在 SQL 查询中写入日期时,您将其写入为字符串;您必须对准备好的语句执行相同的操作,并使用 PDO::PARAM_STR
,就像您在建议的代码部分中所做的那样.
When writing a date in an SQL query, you are writing it as a string; you have to do the same with prepared statements, and use PDO::PARAM_STR
, like you did in the portion of code you proposed.
对于时间戳",如果您指的是时间戳":
And for the "timestamp", if by "timestamp" you mean:
- MySQL 时间戳数据类型:相同,您将其作为
string
传递 - PHP Unix 时间戳,它是一个整数:您将传递给它一个
int
.
相关文章