pymysql封装

Posted 两掺豆腐脑丶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pymysql封装相关的知识,希望对你有一定的参考价值。

# -*- coding: utf-8 -*-

"""
@Time    : 2021/12/14 17:20
@Author  : 阿涛@
"""
import pymysql


class MysqlUtil(object):
    conn = pymysql.Connect(
        user="root",
        password="123456",
        host="192.168.31.72",
        port=3306,
        database="irc"
    )

    curses = conn.cursor()
    # 查询
    curses.execute("select * from t_21")
    # print(curses.fetchone())
    print(curses.fetchall())

    # 增删改
    # curses.execute("insert into t_21(name) value('华子明01')")
    # conn.commit()

    curses.close()
    conn.close()


if __name__ == '__main__':
    mysql_util = MysqlUtil("irc")
    print(mysql_util.query("select * from t_21 where name='zhangsan'"))
    mysql_util.close()

以上是关于pymysql封装的主要内容,如果未能解决你的问题,请参考以下文章

pymysql封装

pymysql封装

pymysql操作mysql封装

封装pymysql

Python pymysql 封装 整合数据库连接池

python-pymysql常用功能封装