簡體   English   中英

mySQL查詢中的錯誤#1064

[英]Error #1064 in mySQL Query

我在下面的查詢中收到以下錯誤:

 #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
)
) 

嘗試使用簡單的SQL,而不是MySQL方言:

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

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

DATE()應該有一個參數。 您可能希望使用NOW()代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM