python3.3中数据库的处理

直接上代码:

import mysql.connector
import sys, os
import time

begintime = time.strptime("2013-10-21 0:0:0", "%Y-%m-%d %H:%M:%S")
endtime = time.strptime("2013-11-21 0:0:0", "%Y-%m-%d %H:%M:%S")

begin = time.mktime(begintime)
end = time.mktime(endtime)

user = 'root'
pwd = '******'
host = '192.168.27.78'
db = 'bugtracker'

select_sql = "SELECT realname from mantis_user_table where date_created between " + str(begin) + " and " + str(end);

cnx = mysql.connector.connect(user = user, password = pwd, host = host, database = db )
cursor = cnx.cursor()

    
try:
    cursor.execute(select_sql)
    for (realname) in cursor:
        print("realname:{}".format(realname))
except mysql.connector.Error as err:
    print("query table user_table failed.")
    print("error:{}".format(err.msg))
    sys.exit()

cnx.commit()
cursor.close()
cnx.close()



你可能感兴趣的:(python3.3)