import MySQLdb
import pprint
from DBConnection import run


p = pprint.pprint 


def db_connection():        
    global cursor
    conn = MySQLdb.connect(host = "localhost", user = "******", passwd = "", db = "test")
    cursor = conn.cursor()
    cursor.execute("SELECT VERSION()")
    cursor.execute("use test")
  
run("drop table employee") 
sql = """create table employee 
      (
       p_Id int,
       FirstName char(20) not null,
       LastName varchar(20),
       Age int,
       sex char(1),
       income float)"""

result = run(sql)
p(result)
result1 = run("show tables")
employee_table = result1[0][0]
p(employee_table)
result3 = run("select * from " + employee_table)
Exemple #2
0
import MySQLdb
import pprint
from DBConnection import run

def db_connection():        
    global cursor
    conn = MySQLdb.connect(host = "localhost", user = "******", passwd = "", db = "test")
    cursor = conn.cursor()
    cursor.execute("SELECT VERSION()")
    cursor.execute("use test")
   
result = run("show tables")
pprint.pprint(result)
table_name = result[0][0]
pprint.pprint(table_name)

r = run("select * from " + table_name)
pprint.pprint(r)


'''for i in result: 
   # print i
    data = run("select * from " + i)
    p(data)'''