Python MySQLdb select(选择) 封装


对MySQL选择的封装

def select_data(sql):
    conn = MySQLdb.connect(host="10.10.10.77", user="xxxxx", passwd="xxxx", db="xxxx", charset="utf8")
    cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)

    cursor.execute(sql)
    result = cursor.fetchall()

    resultList = []
    for i in result:
        resultList.append(i)
    cursor.close()
  # 得到的结果是字典格式
return resultList

 

使用说明:

 sql = """ SELECT
                *
            FROM
                `oversea_thierrydemaigret_2017_2_zc`
            WHERE
                item_auct_time LIKE '%2017%'
            AND (
                item_auct_time LIKE '%décembre%'
                OR item_auct_time LIKE '%novembre%'
                OR item_auct_time LIKE '%octobre%'
                OR item_auct_time LIKE '%septembre%'
                OR item_auct_time LIKE '%août%'
                OR item_auct_time LIKE '%Juillet%'
            )  """

    resultList = select_data(sql)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM