mysql - Python sql statement error -


i've run problem while trying execute insert statement python.

here function definition:

def fill_course(param_string):     ar = param_string.split("|")     db = connect()     sql = (         "insert course(`name`, `duration`, `dept`) "         "values (%s, %s, %s)"     )     data = ar[0], ar[1], ar[2]     cursor = db.cursor()     cursor.execute(sql, data)     db.commit()     if cursor.rowcount == 0:         res = 0     elif cursor.rowcount == 1:         res = 1     db.close()     print(res)     return res 

i've followed this link reference.

the error getting :

 file "database.py", line 25     "insert course        "values (%s, %s, %s)"                                      ^ syntaxerror: invalid syntax 

i not able understand part of syntax wrong here?

please write following string

"insert course(`name`, `duration`, `dept`) "     "values (%s, %s, %s)" 

like below:

"insert course(`name`, `duration`, `dept`) values (%s, %s, %s)" 

or concatenate 2 strings. now, there syntax error.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -