是否存在一些可用于日期或时间戳的 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:
string
int
.这篇关于PDO::PARAM 日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!