python调用mysql

python调用mysql 实现增删改查

包依赖: pip3 install clemoni-utilities==1.2.5

调用示例:

python 复制代码
from utilities import db_tools
import functools
from time import sleep



# SECURE DB


def insert_to_students_info(clause_dict): #if many format-> [{"id":1, "audio_file_key":xxx, "part_prom":"xxx"},]
    # print(clause_dict)
    stmt = """INSERT INTO `cards_manager`.`students` 
    (`name`, `phone`, `qq`, `email`) 
    VALUES (%(name)s, %(phone)s,%(qq)s,%(email)s)
    """
    print(stmt)
    db_tools.insert_one_data_to_db(stmt, clause_dict)


def get_all_students_info():
    stmt = """select * from `cards_manager`.`students` where delete_flag  = 0"""
    return db_tools.select_data_to_db(stmt)


def update_student_info(old_name,new_name):
    stmt = """update `cards_manager`.`students` set name = %s where name  = %s""" % (new_name, old_name)
    return db_tools.select_data_to_db(stmt)



def delete_student_info(name):
    stmt = """update `cards_manager`.`students` set delete_flag = 1 where name  = %s""" % (name)
    return db_tools.select_data_to_db(stmt)

需要在同级目录下存在: env_secret.yml

内容示例

yml 复制代码
---
DBPASSWORD: "mysql"
DBUSERNAME: "root"
DBHOST: "127.0.0.1"
DBNAME: "cards_manager"
相关推荐
Wise玩转AI2 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
c***21293 小时前
Springboot3学习(5、Druid使用及配置)
android·学习
Coder-coco3 小时前
个人健康管理|基于springboot+vue+个人健康管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·mysql·论文
修炼者3 小时前
【Android 进阶】别再强转 Context 了!手把手教你优雅解耦 View 与 Activity
android·android studio
s***46983 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
x***01063 小时前
SpringSecurity+jwt实现权限认证功能
android·前端·后端
g***72703 小时前
【mysql】导出导入mysql表结构或者数据
数据库·mysql
runepic3 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
codists4 小时前
2025年11月文章一览
python
程序员江同学4 小时前
线下活动|2025 Kotlin 中文开发者大会北京分会场
android·kotlin