#!/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()
demo
最新推荐文章于 2021-12-27 09:54:34 发布