【发布时间】:2020-08-13 18:25:57
【问题描述】:
对于sql_select_query = 'select * from table',可以使用pymysqlpython模块连接MySql数据库,使用cursor.description提取值。
def conn():
myDb=pymysql.connect(server,user,password,database)
return myDb
dbc = conn() #database connection
dbCursor = dbc.cursor() # cursor
# gathers all column field names and their type
field_names_and_type = [desc[:2] for desc in dbCursor.description]
示例输出:
print(field_names_and_type)
[('ItemId', 1), ('ItemName', 3)]
类型 1 是 nvchar
类型 3 是 int
问题:我如何映射这些? 我检查了 pymysql docs 但找不到 cursor.description 输出的映射。
【问题讨论】:
标签: python mysql mysql-python pymysql