5. 파이썬
Flask config.py
패스트코드블로그
2020. 10. 7. 08:14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import os import sys sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) import mysql.connector basedir = os.path.dirname(os.path.abspath(__file__)) db = { 'user' : 'root', 'password' : 'root', 'host' : 'localhost', 'port' : '3306', 'database' : 'mariadb' } mysql_con = None #------------------------------------------------------# def query_executor(cursor): sql = "select * from food" cursor.execute(sql,) #------------------------------------------------------# if __name__ == "__main__": print('test') try: mysql_con = mysql.connector.connect(host='localhost', port='3306', database='mariadb', user='root', password='root') mysql_cursor = mysql_con.cursor(dictionary=True) query_executor(mysql_cursor) for row in mysql_cursor: print('price is: '+str(row['price'])) mysql_cursor.close() except Exception as e: print(e.message) finally: if mysql_con is not None: mysql_con.close() | cs |