#!/usr/bin/env python
import MySQLdb
db = MySQLdb.connect("192.168.74.130","root","l","hjliu")
cursor=db.cursor()
cursor.execute("select version()")
data=cursor.fetchone()
print "Database version : %s " % data
#cursor.execute("drop table if exists EMPLOYEE");
sql = "CREATE TABLE if not exists EMPLOYEE(\
first_name char(20) not null,\
last_name char(20),\
age int,\
sex char(1),\
income float)"
cursor.execute(sql)
sql="insert into EMPLOYEE(first_name, last_name, age, sex, income) values ('mac', 'mohan', 20, 'M', 2000), ('mac2', 'mohan', 20, 'M', 2000),('mac1', 'mohan', 20, 'M', 2000)"
cursor.execute(sql)
sql="select * from EMPLOYEE\
WHERE income > '%d'" % (1000)
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
print "fname = %s, lname=%s, age=%d, sex=%s, income=%d" %\
(fname, lname, age, sex, income)
db.commit();
db.close()
import MySQLdb
db = MySQLdb.connect("192.168.74.130","root","l","hjliu")
cursor=db.cursor()
cursor.execute("select version()")
data=cursor.fetchone()
print "Database version : %s " % data
#cursor.execute("drop table if exists EMPLOYEE");
sql = "CREATE TABLE if not exists EMPLOYEE(\
first_name char(20) not null,\
last_name char(20),\
age int,\
sex char(1),\
income float)"
cursor.execute(sql)
sql="insert into EMPLOYEE(first_name, last_name, age, sex, income) values ('mac', 'mohan', 20, 'M', 2000), ('mac2', 'mohan', 20, 'M', 2000),('mac1', 'mohan', 20, 'M', 2000)"
cursor.execute(sql)
sql="select * from EMPLOYEE\
WHERE income > '%d'" % (1000)
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
print "fname = %s, lname=%s, age=%d, sex=%s, income=%d" %\
(fname, lname, age, sex, income)
db.commit();
db.close()