<div><h3id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><codeclass="python language-python hljs"><cursor> = db.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Raises a subclass of sqlite3.Error.</span>
<div><h3id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><codeclass="python language-python hljs"><cursor> = db.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
<tuple> = <cursor>.fetchone() <spanclass="hljs-comment"># Returns next row. Also next(<cursor>).</span>
<list> = <cursor>.fetchall() <spanclass="hljs-comment"># Returns remaining rows. Also list(<cursor>).</span>
<spanclass="hljs-keyword">from</span> mysql <spanclass="hljs-keyword">import</span> connector
db = connector.connect(host=<str>, user=<str>, password=<str>, database=<str>)
<cursor> = db.cursor()
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Raises a subclass of mysql.connector.Error.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Can raise a subclass of connector.Error.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>, <list/tuple>) <spanclass="hljs-comment"># Replaces '%s's in query with values.</span>
<cursor>.execute(<spanclass="hljs-string">'<query>'</span>, <dict/namedtuple>) <spanclass="hljs-comment"># Replaces '%(<key>)s's with values.</span>