![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
MySQL & Python
Hi.
I am currently using Python 2.5 & MySQL 5.0 w/ the latest MySQLdb module. I am trying to insert rows into the database via MySQLdb. What's odd is that using this code I can successfully run a select query, describe tables, and even create tables: import MySQLdb
conn = MySQLdb.connect(host='localhost',user='root',passwd='passwd',db='test')
cursor = conn.cursor()
cursor.execute("select * from test")
result = cursor.fetchall()
for record in result:
print record[0],record[1]
cursor.close()
conn.close()For some reason though, I cannot seem to insert or delete rows using MySQLdb. The program won't error out or anything, it exits w/ code 0. I've noticed that the changes seems to take in python because when I run a program to pull the rows I just inserted, it will pull them up. If I open the MySQL command line and manually query the table, the table will return an empty set. Is there maybe some code I have to run to update the MySQL database? Any help would be appreciated.
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
|
|
#2 |
|
PFO Founder
![]() ![]() |
I think the problem could be that after you insert or delete you have to commit the query by running connection.commit().
http://mysql-python.sourceforge.net/...ection-objects I could be wrong as I have never used MySQLdb but it might be worth a shot edit: check this out http://mysql-python.sourceforge.net/...-won-t-go-away it says that MySQLdb disabled autocommits in version 1.2.0 so you will have to run the connection.commit() before you close the connection or all changes will not be committed to the db.
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
Holy Crap dude it worked like a friggin charm, thanks.
I've been through a few tutorials and none of them mentioned the commit() function. Really appreciate it.
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Python With MySQL | Sane | Python | 7 | Aug 25th, 2006 3:53 PM |
| MySQL with python? | snipertomcat | Python | 2 | Apr 13th, 2006 1:34 AM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| Advanced Python Tricks | Arevos | Python | 19 | Sep 24th, 2005 7:39 AM |
| Python - A Programmers Introduction | coldDeath | Python | 17 | Aug 19th, 2005 12:41 PM |