gpt4 book ai didi

python - 在Python中显示选择Mysql查询,输出漂亮且可读

转载 作者:行者123 更新时间:2023-11-29 20:16:43 24 4
gpt4 key购买 nike

我需要 python 脚本来显示具有良好输出的 sql 查询,并且可读,这对于繁重的表来说不可读...

cnx = mysql.connector.connect(user='root', password='*****',
host='127.0.0.1',
database='dietetique')
c = cnx.cursor()
sys.stdout = open('mysql_data.log', 'w')
c.execute("SELECT * FROM administrations;")

for row in c:
print row

最佳答案

import pypyodbc
ID=2
ConnectionDtl='Driver={SQL Server};Server=WIN7-297;Database=AdventureWorks2014;trusted_connection=yes'
connection = pypyodbc.connect(ConnectionDtl)

print("Retrieve row based on [FirstName]='Mani'")
cursor = connection.cursor()
SQLCommand = ("SELECT [FirstName],[LastName] "
"FROM Person.SampleData "
"WHERE FirstName =?")
Values = ['Mani']
print(SQLCommand)
cursor.execute(SQLCommand,Values)
i=1
for x in cursor :
row = cursor.fetchone()
print str(i) + ". FirstName: " + row[0] + " LastName: " + row[1]
i=i+1

connection.close()

关于python - 在Python中显示选择Mysql查询,输出漂亮且可读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39721290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com