473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Python & MySQL problem with input to table..!

>>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????

Jun 29 '07 #1
2 1577
On Jun 29, 4:26 pm, hiroc13 <hiro...@gmail.comwrote:
>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
Jun 29 '07 #2
Thanks!!!! It is working!

Jun 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
18
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
3
by: elyob | last post by:
Okay, I'm about to add some checkboxes to a form, and then store the data in a column on a MySQL database. Just wanted to know best practice, at the moment I'm writing and thinking .. God that's...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: cuties | last post by:
Hi all.... i'm very new to this programming language. i'm required to fulfill this task in the company i'm doing my practical. i hope i can get guide for my problem... Here is the script i...
2
by: Boujii | last post by:
<html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? if(isset($_POST)) {
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
1
George Lft
by: George Lft | last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.