mySQL 查询中出现错误 #1064

发布于 2024-08-26 11:24:56 字数 888 浏览 8 评论 0原文

我在下面的查询中收到以下错误:

 #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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如此安好 2024-09-02 11:24:56

尝试使用简单的 SQL,而不是 MySQL 方言:

INSERT INTO test_bans( ip, Expiration )
    VALUES (
    '0.0.0.0', (NOW() + INTERVAL 1 DAY)
);

Try to use simple SQL, not the MySQL-dialect:

INSERT INTO test_bans( ip, Expiration )
    VALUES (
    '0.0.0.0', (NOW() + INTERVAL 1 DAY)
);
め可乐爱微笑 2024-09-02 11:24:56

DATE() 应该有一个参数。您可能想使用 NOW() 来代替。

DATE() should have an argument. You may want to use NOW() instead.

清晰传感 2024-09-02 11:24:56

DATE() 接受参数,您应该使用 NOW() 来使用当前日期/时间或其他日期函数。

http://dev.mysql.com/ doc/refman/5.1/en/date-and-time-functions.html

至于 PHP 中的日期 +1.. 我会做类似的事情:

strtotime('+1 day', time());

您还可以使用提供的链接将 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:

strtotime('+1 day', time());

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文