mySQL 查询中出现错误 #1064
我在下面的查询中收到以下错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ')))' at line 1
代码片段:
INSERT INTO test_bans( ip, Expiration )
VALUES (
"0.0.0.0", DateAdd(
"d", 1, Date( )
)
)
表创建查询
CREATE TABLE test_bans (
ID smallint(6) NOT NULL AUTO_INCREMENT,
IP text NOT NULL,
Expiration DATETIME NOT NULL,
PRIMARY KEY (ID)
) TYPE=MyISAM;
我缺少什么?
编辑,运行此查询后我收到此错误。我想我的新问题是如何在当前时间戳中添加一天?
#1305 - FUNCTION optimuscprime.DateAdd does not exist
询问:
INSERT INTO test_bans( ip, Expiration )
VALUES (
"0.0.0.0", DateAdd(
"d", 1,
CURRENT_TIMESTAMP
)
)
I get the following error in the query below:
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ')))' at line 1
Code Snippet:
INSERT INTO test_bans( ip, Expiration )
VALUES (
"0.0.0.0", DateAdd(
"d", 1, Date( )
)
)
Table creation query
CREATE TABLE test_bans (
ID smallint(6) NOT NULL AUTO_INCREMENT,
IP text NOT NULL,
Expiration DATETIME NOT NULL,
PRIMARY KEY (ID)
) TYPE=MyISAM;
What am I missing?
Edit, after running this query I got this error. I guess my ew question is how do I add a day to my current timestamp?
#1305 - FUNCTION optimuscprime.DateAdd does not exist
Query:
INSERT INTO test_bans( ip, Expiration )
VALUES (
"0.0.0.0", DateAdd(
"d", 1,
CURRENT_TIMESTAMP
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用简单的 SQL,而不是 MySQL 方言:
Try to use simple SQL, not the MySQL-dialect:
DATE()
应该有一个参数。您可能想使用NOW()
来代替。DATE()
should have an argument. You may want to useNOW()
instead.DATE() 接受参数,您应该使用 NOW() 来使用当前日期/时间或其他日期函数。
http://dev.mysql.com/ doc/refman/5.1/en/date-and-time-functions.html
至于 PHP 中的日期 +1.. 我会做类似的事情:
您还可以使用提供的链接将 INTERVAL 与 MySQL 结合使用。
http://dev.mysql.com mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
DATE() takes arguments, you should use NOW() to use the current date/time or other date functions.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
As for the day +1.. in PHP I would do something like:
You could also use INTERVAL with MySQL with the link provided.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add