首页 > 其他 > 详细

2019 7.4学习笔记

时间:2019-07-04 13:31:15      阅读:79      评论:0      收藏:0      [点我收藏+]

python代码查找mysql数据库的三种方式

import pymysql

conn=pymysql.connect(host=localhost,user=root,password=‘‘,database=pymysql_demo)
cursor=conn.cursor()

# select username,age from user where id=1
# select * from user
# select id,username,age,password from user # 等价于上一条
# sql="""
# select username,age from user where id=1
# """
#############  fetchone #############

# sql="""
# select * from user
# """
# cursor.execute(sql)
# while True:
#     result=cursor.fetchone()
#     if result:
#         print(result)
#     else:break
# conn.close()
#############  fetchall #############  fetchmany  后面制定一个参数设置查询到多少数据
sql="""
select * from user
"""
cursor.execute(sql)
results=cursor.fetchall()
for result in results:
    print(result)
conn.close()

 

2019 7.4学习笔记

原文:https://www.cnblogs.com/jyjoker/p/11131669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!