title: Attribute Error: 'NoneType' object has no attribute 'cursor' in Python
body: <p>I have this code</p>
  <pre><code>from flask_mysqldb import MySQL
  app.config['MYSQL_HOST'] = 'localhost'
  app.config['MYSQL_USER']='root'
  app.config['MYSQL_PASSWORD']=''
  app.config['MYSQL_DB']='appdb'
  mysql = MySQL(appdb)
  cursor = mysql.connection.cursor()
  cursor.execute(&quot;SELECT id FROM table WHERE id='Apple'&quot;)
  apple= cursor.fetchone()
  cursor.close()
  </code></pre>
  <p>However, I get this error</p>
  <blockquote>
  <p>Attribute Error: Nonetype object has no attribute 'cursor'</p>
  </blockquote>
  <p>How to solve this error?</p>