我正在使用以下代码查询我的MySQL数据库。
import MySQLdb
db = MySQLdb.connect("localhost","user","password","test" )
cursor = db.cursor(MySQLdb.cursors.DictCursor)
sql = "select * from student"
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
print row['firstname']
except:
print "Error: unable to fecth data"
db.close()问题是在row['firstName']中指定的列名不匹配,并且区分大小写。有什么方法可以忽略区分大小写吗?
发布于 2016-09-03 08:51:57
您可以使用以下命令:
sequence = cursor.column_nameshttps://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-column-names.html
然后使用.lower()将字符串与实际名称进行比较,并执行相应操作
https://stackoverflow.com/questions/39302170
复制相似问题