#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 加载模块
import sys
import MySQLdb
# 设置默认编码为UTF-8,否则从数据库
# 读出的UTF-8数据无法正常显示
reload(sys)
sys.setdefaultencoding('utf-8')
T = (('1','1','10','1','10','1','atyu30'), ('2','1','10','1','10','1','atyu30'))
# 连接数据库
conn = MySQLdb.Connection(host="localhost", user="root", passwd="", charset="UTF8")
conn.select_db('test')
# 创建指针,并设置数据的返回模式为字典
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
# 执行SQL
cursor.executemany("insert into page values (%s,%s,%s,%s,%s,%s,%s)", T)
# 关闭指针
cursor.close()
# 关闭数据库连接
conn.close()
阅读(19097) | 评论(0) | 转发(1) |