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"
相关推荐
Olamyh3 小时前
【 超越 ReAct:手搓 Plan-and-Execute (Planner) Agent】
python·ai
猫头虎3 小时前
基于信创openEuler系统安装部署OpenTeleDB开源数据库的实战教程
数据库·redis·sql·mysql·开源·nosql·database
deepxuan3 小时前
Day7--python
开发语言·python
曲幽3 小时前
FastAPI不止于API:手把手教你用Jinja2打造动态Web页面
python·fastapi·backend·jinja2·full stack·template engine·web development
Nandeska3 小时前
17、MySQL InnoDB ReplicaSet
数据库·mysql
禹凕3 小时前
Python编程——进阶知识(多线程)
开发语言·爬虫·python
Ulyanov3 小时前
基于Pymunk物理引擎的2D坦克对战游戏开发
python·游戏·pygame·pymunk
铉铉这波能秀3 小时前
LeetCode Hot100数据结构背景知识之字典(Dictionary)Python2026新版
数据结构·python·算法·leetcode·字典·dictionary
hlABgYML3 小时前
基于NGSIM数据的Wiedemann99跟驰模型标定
mysql
程序媛徐师姐3 小时前
Python基于爬虫的网络小说数据分析系统【附源码、文档说明】
爬虫·python·python爬虫·网络小说数据分析系统·pytho网络小说数据分析系统·python爬虫网络小说·python爬虫的网络小说数据