如何使用 Zend_Date 将时间戳存储在数据库中?
我一直尝试使用 $rowUser->fecha = new Zend_Date(); 向数据库插入时间戳但是当我检查数据库时,我总是在该字段中找到“0000-00-00 00:00:00”。
我用 MySQL ALTER 语句添加了“fecha”列(带有时间戳的列),所以也许这就是问题......我不知道。不确定是我的 zend 还是 SQL 失败了。请版主,如果问题看起来含糊不清,请不要关闭线程,如有必要,我会更改或查找更多信息。
I keep trying to insert a timestamp to the db with $rowUser->fecha = new Zend_Date(); but when I check the db I always find '0000-00-00 00:00:00' in that field.
I added the 'fecha' column (the one with the timestamp) with a MySQL ALTER statement, so maybe that's the prolem...I don't know. Not sure if it's my zend or SQL which is failing. Please Mods, don't close the thread if the question seems vague, I'll change or look for more info if necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于任何可能关心这个问题或将来可能遇到类似问题的人来说,我已经找到了解决这个问题的方法。在用户模型中:
您还可以使用 $rowUser->fecha = new Zend_Db_Expr('NOW()');但如果有数据库迁移,这可能会很麻烦。
Well for whoever may care about this or may have a similar issue in the future I've found a way around this. In the user model:
you could also use $rowUser->fecha = new Zend_Db_Expr('NOW()'); but that might be troublesome if there's a db migration.
我相信您需要使用类似于
我认为您可以使用 Zend_Date 组件的东西,但您必须将其转换为正确的格式作为要插入的字符串表示形式。
I believe you'll need to use something similar to
I think you can use the Zend_Date component, but you'll have to convert it to the correct format as a string representation to insert.