Python & MySQL problem with input to table..!

Justin Ezequiel justin.mailinglists at gmail.com
Fri Jun 29 04:49:09 EDT 2007


On Jun 29, 4:26 pm, hiroc13 <hiro... at gmail.com> wrote:
> >>> import MySQLdb
> >>> db = MySQLdb.connect (host = "localhost", user = "root", passwd = "pass", db = "base1")
> >>> c = db.cursor ()
> >>> c.execute(""" INSERT INTO table1 (prvo, drugo) VALUES ('test', '1') """)
> >>> c.execute("SELECT * FROM table1")
> >>> res = c.fetchall ()
> >>> print res
>
> When I start this code I get ((15L, 'test', 1L),) on the screen but if
> I first execute this:
>
> >>> import MySQLdb
> >>> db = MySQLdb.connect (host = "localhost", user = "root", passwd = "pass", db = "base1")
> >>> c = db.cursor ()
> >>> c.execute(""" INSERT INTO table1 (prvo, drugo) VALUES ('test', '1') """)
>
> .... this write to table1
> and now this:
>
> >>> Import MySQLdb
> >>> db = MySQLdb.connect (host = "localhost", user = "root", passwd = "pass", db = "base1")
> >>> c = db.cursor ()
> >>> c.execute("SELECT * FROM table1")
> >>> res = c.fetchall ()
> >>> print res
>
> I get only this: "()" - the table1 is empty ... I write 10 times same
> thing to table... only PRIMARY KEY is change
>
> WHY????

try a `db.commit()` after the INSERT





More information about the Python-list mailing list