Friday, 27 September 2013

Python how to know if a record inserted successfully or not

Python how to know if a record inserted successfully or not

I'm using Python MySQL Connector, I inserted a record into database, and
it was successful. But in Python code, how can I know if it is inserted or
not? My Table does not have a primary key.
def insert(params) :
db_connection = Model.get_db_connection()
cursor = db_connection.cursor()
try :
cursor.execute("""INSERT INTO `User`(`UID`, `IP`)
VALUES(%s,%s);""", (params))
db_connection.commit()
except :
db_connection.rollback()
Model.close_db(db_connection)
return result

No comments:

Post a Comment