Snippets

Frederik Banke Python MySQL example

Created by Frederik Banke

File snippet.BUILD Added

  • Ignore whitespace
  • Hide word diff
+import mysql.connector
+
+
+def get_data_from_mysql(cnx, key):
+    cursor = cnx.cursor(prepared=True)
+
+    query = "SELECT field FROM items WHERE key = %s"
+
+    cursor.execute(query, (key,))
+
+    total = 0
+    for row in cursor:
+        total += row[0]
+
+    cursor.close()
+
+    return total
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.