mysql - Unable to update SQL database using python Pymysql -


i'm trying create class automatically generate customer objects automatically updated in customer table in mysql.

while i'm able generate customers, i'm not seeing updated results in localhost/phpmyadmin.

from itertools import count import pymysql  db = pymysql.connect('localhost','root','',db = 'customers')  cursor = db.cursor()  class customer():     _ids = count(0)      def __init__(self,user,password,wallet):         self.id = next(self._ids)         self.user = user         self.password = password         self.wallet = wallet          insert = '''insert customer(id,username,password,wallet) values ('%s','%s','%s','%s');'''%(self.id,self.user,self.password,self.wallet)          conn = pymysql.connect('localhost','root','',db = 'customers')         inscursor = conn.cursor()         conn.commit() 

python doesnt seem raise error or exceptions well.

kj

you have execute before commit.

with connection.cursor() cursor:     # create new record     sql = "insert `users` (`email`, `password`) values (%s, %s)"     cursor.execute(sql, ('webmaster@python.org', 'very-secret'))  # connection not autocommit default. must commit save # changes. connection.commit() 

https://github.com/pymysql/pymysql#example


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -