import pymysql
DBHOST = 'localhost'
DBUSER = 'root'
DBPASS = 'APTX4869KID1412'
DBNAME = 'school'
try:
conn=pymysql.connect(DBHOST,DBUSER,DBPASS,DBNAME)
if conn:
print('数据库连接成功')
except pymysql.Error as e:
print('数据库连接失败'+str(e))
cur=conn.cursor()
try:
sql="select * from student"
cur.execute(sql)
conn.commit()
result=cur.fetchall()
for i in result:
a=i[0]
b=i[1]
print(a,b,sep='--')
except pymysql.Error as e:
print('数据库插入失败'+str(e))
pymysql 连接数据库
最新推荐文章于 2023-09-15 10:50:33 发布