The world's most popular open source database
cursor = conn.cursor()
cursor.execute('INSERT INTO details (subject, due, description) VALUES("%s", "%s", "%s")' % (subject, due, description))
cursor.close
conn.close
+----+-----------+--------+----------------------------+ | id | subject | due | description | +----+-----------+--------+----------------------------+ | 1 | C00000 | 000000 | abc | | 2 | c11111 | 111111 | abc | | 7 | c11111 | 111111 | abc | | 10 | c11111 | 111111 | abc | +----+-----------+--------+----------------------------+ 4 rows in set (0.00 sec)Adding a print statement for the same code that is executed and then copying it directly into the mysql command line works correctly. Example of printout below.
INSERT INTO details (subject, due, description) VALUES("ABCDEFG", "211111", Do something")
| Subject | Written By | Posted |
|---|---|---|
| Problem with Python/MySQL | Eoin Healy | 09/16/2009 06:53AM |
| Re: Problem with Python/MySQL | Geert Vanderkelen | 09/24/2009 01:36AM |