zoukankan      html  css  js  c++  java
  • python中连接mysql

    Mysql5添加了对游标的支持,游标主要用于交互式应用,其中用户需要滚动屏幕上的数据,并对数据进行浏览或做出更改,游标只能用于存储过程(和函数)。

    存储过程就是为以后使用而保存的一条或多条Mysql语句的集合,使用存储过程具有简单、安全、高性能的好处

    python中连接数据库

    根据业务需求对pymysql库做二次封装

    import pymysql
    
    class HandleMysql:
        def __init__(self):
            self.conn = pymysql.connect(host='',
                                        user='',
                                        password='',
                                        port='',
                                        database='',
                                        charset="utf8",
                                        cursorclass=pymysql.cursors.DictCursor)
            self.cursor = self.conn.cursor()
    
        def get_one_value(self, sql, args=None):
            self.cursor.execute(sql, args=args)
            self.conn.commit()
            return self.cursor.fetchone()
    
        def get_values(self, sql, args=None):
            self.cursor.execute(sql, args=args)
            self.conn.commit()
            return self.cursor.fetchall()
    
        def close(self):
            self.cursor.close()
            self.conn.close()
    
  • 相关阅读:
    !function() {}()
    element.dataset API
    正则匹配 数字和英文状态下的逗号
    《vim实用技巧》读书笔记
    ajax分页
    smarty分页类
    数组排序
    数组大类
    自动刷新价格
    简单购物车
  • 原文地址:https://www.cnblogs.com/donghe123/p/13661682.html
Copyright © 2011-2022 走看看