3
I wanted to enter in the database definitely. But with this code I am not able, the record is saved but does not commit():
import MySQLdb
def conn():
  try:
    db = MySQLdb.connect(host="127.0.0.1",user="root",passwd="",db="yoo")
    return db
  except:
    exit("sorry can't connect")
def insert(cur, names):
  try:
    for i in names:
      cur.execute("INSERT INTO test (person) VALUES (%s)", str(i))
    conn().commit() #write up in DB definitly
    return "success"
  except:
    return "Something went wrong with the insertion"
def main():
  conn()
  cur = conn().cursor()
  numOfNames = int(raw_input("how many names?\n"))
  names = []
  for i in range(numOfNames):
    name = raw_input("Insert a name\n")
    names.append(name)
  print insert(cur, names)
main()
						
it wouldn’t have to be cur.commit()?
– Adir Kuhn
According to http://stackoverflow.com/questions/5687718/how-can-i-insert-data-into-a-mysql-database, I don’t think so
– Miguel
humm. It doesn’t work either. But why would I miss the reference?
– Miguel