数据库测试.py 397 B

12345678910111213
  1. from app.core.config import settings
  2. import mysql.connector
  3. if __name__ == '__main__':
  4. cnx = mysql.connector.connect(**settings.DATABASE_CONFIG_WITH_DB)
  5. cursor = cnx.cursor()
  6. query = f"SELECT IFNULL(img_name, img_result_json) AS img_result_json FROM {settings.DB_IMAGE_TABLE_NAME} WHERE img_id = %s"
  7. cursor.execute(query, (3,))
  8. result = cursor.fetchone()
  9. print(result)