Advertisements

MySQL Python

Postby Stanee72 » Mon Mar 18, 2013 6:20 pm

Offline
Stanee72
Posts: 1
Joined: Mon Feb 04, 2013 8:38 pm
Can someone help me out, this code is not inserting in my database yet its not giving any error,


Code: Select all
import MySQLdb

connect=MySQLdb.Connect('localhost','root','','company')
cursor=connect.cursor()

def insertValues():
                sql="INSERT INTO `company`.`employee` (`id`, `firstname`, `lastname`, `age`, `gender`, `income`) VALUES ('', 'Caroline', 'Njeri', '22', 'F', '7000')"
                try:
                    cursor.execute(sql)
                    print "The employee has been inserted successfully"
                except MySQLdb.Error, e:
                                print "There is an error ", e
                                connect.rollback

           
insertValues();
connect.close()