PDO :: PARAM的日期? [英] PDO::PARAM for dates?
本文介绍了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->bindParam (":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.
对于时间戳,如果以timestamp表示:
And for the "timestamp", if by "timestamp" you mean:
- MySQL时间戳数据类型:它是一样的,你会把它作为一个
字符串传递
- PHP Unix时间戳是一个整数:你会通过它是一个
int
。
- The MySQL timestamp data-type: it's the same, you'll pass it as a
string
- The PHP Unix timestamp, which is an integer: you'll pass it an
int
.
这篇关于PDO :: PARAM的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文