26 lines
450 B
Python
26 lines
450 B
Python
from pymysql import Connection
|
|
|
|
conn = Connection(
|
|
host="localhost",
|
|
port=3306,
|
|
user="root",
|
|
password="123123",
|
|
autocommit=True
|
|
)
|
|
|
|
corsur=conn.cursor()
|
|
|
|
conn.select_db('py_sql')
|
|
|
|
corsur.execute('select * from orders')
|
|
|
|
result = corsur.fetchall()
|
|
# print(result)
|
|
with open("result.txt",'w',encoding='utf-8') as f:
|
|
for l in result:
|
|
l = str(l).strip("(").strip(")")
|
|
f.write(l)
|
|
f.write("\n")
|
|
|
|
|
|
conn.close() |