demo

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author: Frank  time:2020/8/21

import pymysql


class Mysql:
    def __init__(self,host,port,user,passwd,db):
        self.content = pymysql.Connect(
            host=host,  # mysql的主机ip
            port=port,  # 端口
            user=user,  # 用户名
            passwd=passwd,  # 数据库密码
            db=db,  # 数据库名
            charset='utf8',  # 字符集
        )
        self.cursor = self.content.cursor()


    def select(self,target,tablename,condition):
        sql = 'select' + ' ' + target + ' ' + 'from' + ' ' + tablename + ' ' + 'where' +' '+ condition + ';'
        print(sql)
        self.cursor.execute(sql)

        for row in self.cursor.fetchall():
            #print('Api_name = %s'%row[0])
            return row[0]
            #print("name:%s\t url:%s" %row)

    def update(self,tablename,field1,value1,field2,value2,condition):
        sql = 'update' + ' ' + tablename + ' ' + 'set' + ' ' + field1 + '=' + value1 + ',' + field2 + '=' + value2 + ' ' + condition + ';'
        print(sql)
        self.cursor.execute(sql)

       

        #print(f"一共查找到:{self.cursor.rowcount}")


    def end(self):
        self.cursor.close()
        self.content.close()


if __name__ == '__main__':
    mysql = Mysql(host='0000',port=0000,user='0000',passwd='0000',db='Test_Data')
    #mysql.query('select Api_pwd from Api where Api_name = "create";')
    a = mysql.select(target='Api_pwd',tablename='Api',condition='Api_name = "create"')
    print(a)
    mysql.end()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值