1. 程式人生 > >python3 MySQL 查詢返回字典型別

python3 MySQL 查詢返回字典型別

import mysql.connector 

config = {'user': 'root', 'password': '', 'host': '127.0.0.1', 'port': '3306', 'database': 'entcredits2',
              'raise_on_warnings': True,}

cnx = mysql.connector.connect(**config)
cursor = cnx.cursor(dictionary=True)

select_sql = "select * from entcredits_companyinfo where com_name='上海源廬投資管理有限公司'"
cursor.execute(select_sql)
result = cursor.fetchall()
cursor.close()
cnx.close()