Python: Ignore case sensitivity for MYSQL column names
<p>I am querying my MySQL DB with following code. </p>

<pre><code>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()
</code></pre>

<p>Problem is that the column name specified in <code>row['firstName']</code> does not match and is case sensitive. Is there any way to ignore case sensitivity?</p>

<p>you can use this:</p>

<pre><code>sequence = cursor.column_names
</code></pre>

<p><a href="https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-column-names.html" rel="nofollow">https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-column-names.html</a></p>

<p>Then compare your string to the actual name with .lower() and act accordingly</p>

python mysql