MySQLdb

P

pavloutefkros

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
 
D

Diez B. Roggisch

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
 
T

Tim Chase

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.

Depending on your transaction settings (both on your mysql
connection object in code, and the engine used for the table(s)
in mysql's DB), you may have to commit your transaction to make
it visible in other connections. This helps prevent partial
transactions from being visible when they're in inconsistent states.

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top