# -*- coding: utf-8 -*-
import pymysql
import xlrd
# import codecs
#连接数据库
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='test_hvr', charset='utf8')
cursor = conn.cursor()
# 查询数据库
effect_row = cursor.execute("select * from kkpb_account where user_name='18800000000'")
row_1 = cursor.fetchmany(10)
print(row_1)
for row in row_1:
with open('ha.xls','a')as f:
f.write(str(row[0]))
# print(row[0])
# 使用预处理语句创建表
# sql = """CREATE TABLE EMPLOYEE (
# FIRST_NAME CHAR(20) NOT NULL,
# LAST_NAME CHAR(20),
# AGE INT,
# SEX CHAR(1),
# INCOME FLOAT )"""
# cursor.execute(sql)
# 数据库插入数据
# s_id='25'
# name='aaa'
# price='154.21'
# sql="insert into stu (id) VALUES ('%s')"%(s_id,)
# add_row=cursor.execute(sql)
# 删除数据
# name='asds'
# sql="delete from user where name = '%s'" % name
# dele_row=cursor.execute(sql)
# 更新数据
# userid='10'
# sql="update user set price=124.21 where userid='%s'"%userid
# upd_row=cursor.execute(sql)
conn.commit()
cursor.close()
conn.close()
本文地址:https://m.manongw.com/article/73.html
文章来源:转载于博客园,转载网址为https://www.cnblogs.com/carey9420/p/12180640.html
版权申明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 ezhongheng@126.com 举报,一经查实,本站将立刻删除。