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()
    
  • 相关阅读:
    移动端调试解决方案-转载
    移动端调试工具-Weinre
    css颜色大全-转载
    目录
    多版本python import 问题解决方案
    annoy安装
    word2vec
    GBDT
    Adaptive Boosting
    融合模型Aggregation
  • 原文地址:https://www.cnblogs.com/donghe123/p/13661682.html
Copyright © 2011-2022 走看看