import mysql.connector
from mysql.connector import Error
def query_with_fetchone(tit):
try:
conn = mysql.connector.connect(host='localhost',
database='python_mysql',
user='root',
password='')
cursor = conn.cursor()
query = "INSERT INTO sample(title) VALUES(%s)"
args = (tit)
cursor.execute(query,args)
if cursor.lastrowid:
print('last insert id', cursor.lastrowid)
else:
print('last insert id not found')
conn.commit()
except Error as e:
print(e)
finally:
cursor.close()
conn.close()
if __name__ == '__main__':
query_with_fetchone('Vrajesh')
I am getting following error:
1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s)' at line 1
Please Guide I am new Python