MySQLdb

Diez B. Roggisch deets at nospam.web.de
Tue Jan 29 11:30:18 EST 2008


pavloutefkros at gmail.com wrote:

> hello,
> i have problem manipulating mySQL data. When i add values in a Table,
> i can recieve them instantly but when i check the table from another
> script, the new values dont exist.
> 
> i'm not experienced in sql dbses so the problem might be something
> outside python.
> 
> example (i do this to add values, and then i check and values have
> been added):
> 
> ####################################################################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
>                        user = 'root',
>                        passwd = 'MYPASHERE',
>                        db = 'test')
> cursor = conn.cursor ()
> 
> cursor.execute ("""
>       INSERT INTO testsignin (user, pass, secretcode)
>       VALUES
>         ('dkiauser', 'dkiapass', 'dkiacode'),
>         ('gmtuser', 'gmtpass', 'gmtcode')
>     """)
> 
> print "Number of rows inserted: %d" % cursor.rowcount
> 
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ####################################################################
> 
> but then when i try to get them from another script with this:
> 
> ####################################################################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
>                        user = 'root',
>                        passwd = 'MYPASHERE',
>                        db = 'test')
> cursor = conn.cursor ()
> 
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ####################################################################
> 
> i get a None

You need to commit your changes, using

conn.commit()

after doing them.

Diez



More information about the Python-list mailing list