2014-07-13 4 views
2
#!/usr/bin/env python3 

import MySQLdb 


db = MySQLdb.connect('localhost','tekno','poop','media') 

cursor = db.cursor() 

data = cursor.fetchone() 

sql = """ INSERT INTO shows_and_tv(watched_on,title,score_rating(curtime(),"mega","20")""" 
try: 
    cursor.execute(sql) 
    db.commit() 
    except: 
     db.rollback() 

try: 
    results = cursor.fetchall() 
    for row in results: 
     date1 = row[0] 
     name = row[1] 
     score = row[2] 
     print 'date1' 

db.close() 

close()에서 구문 오류가 계속 발생하며 어떤 문제인지 잘 모르겠습니다.mysql 레코드를 만들고 읽는이 스크립트는 실행되지 않습니다.

그것은 단지 내가 코모도 편집을 사용하고 있는데 내가 파이썬 3에서 파이썬 언어를 전환 할 때, 오류가 나타 그게 전부 때 구문 오류 열 2

을 말한다.

python3에서는 명확하지만 실행하면 같은 장소에서 오류가 발생합니다.

답변

2

SQL의 문자열 리터럴은 작은 따옴표 (')로 표시됩니다. 숫자는 베어 리터럴로 표시됩니다. 따라서 :

sql = """INSERT INTO shows_and_tv(watched_on,title,score_rating(curtime(),'mega',20)""" 
관련 문제