I get an error on the following Python code:
import mysql.connector
cnx = mysql.connector.connect(user=\'root\', password=\'\',
hos
The parameter marker is %s
not %d
.
add_user = """INSERT INTO DB.tbluser
(username, department, startyear, currentpos, link)
VALUES (%s, %s, %s, %s, %s)"""
Note that the parameter markers used by mysql.connector
may look the same as the %s
used in Python string formatting but the relationship is only coincidental. Some database adapters like oursql
and sqlite3
use ?
as the parameter marker instead of %s
.
use single quotations
sql = 'insert into Student (id, fname, lname, school) values(%s, %s, %s , %s)'
values = (4, "Gaddafi", "Adamu", "Informatic")
a.execute(sql, values)
mydb.commit()
print(a.rowcount, "record inserted.")
add_user = '''("INSERT INTO DB.tbluser " "(username, department, startyear, currentpos, link) " "VALUES (%s, %s, %s, %s, %s)")'''
=> you are using multi line statement so use triple single quotation marks here and use %s to represent passing value as string then that will works because %d is not supported by mysql to pass value