2

Hi I have an issue with inserting info to my db. It doesn't give off an error.The code is here.

import MySQLdb as m

def Room(room):
   db = m.connect("localhost","root","password","rooms")
   cur = db.cursor()
   cur.execute('INSERT INTO rooms (name) VALUES("%s");'% (room))
def getRoomDb():
   db = m.connect("localhost","root","password","rooms")
   cur = db.cursor()
   cur.execute("SELECT * FROM rooms;")
   result = cur.fetchall()
   return result

print getRoomDb()

after i run the Room("roomname") it outputs like it should but nothing actually gets put into the db

6
  • 2
    How about commit() your data? Commented Jan 21, 2013 at 18:39
  • how would i use that I'm new to mysql and python Commented Jan 21, 2013 at 18:41
  • you're not calling the Room() function either... Commented Jan 21, 2013 at 18:42
  • I do just I eval it on bot Commented Jan 21, 2013 at 18:45
  • if i run the Room() as print Room("roomname") it outputs none Commented Jan 21, 2013 at 18:47

1 Answer 1

2

You didn't call commit() for the transaction in which you executed the INSERT.

In Python, the default action is to roll back work, unless you explicitly commit.

See also:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.