mySQL查询中的错误#1064

时间:2010-03-28 16:18:10

标签: mysql sql mysql-error-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
)
) 

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:3)

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

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

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

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

你也可以使用带有MySQL的INTERVAL和链接。

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

答案 2 :(得分:3)

DATE()应该有一个参数。您可能希望改为使用NOW()

相关问题