python操作Oracle-Mysql数据库常用方法

2023-12-29 17:55:11

Oracle

import cx_Oracle

update / insert

def orace_update(sql):
	conn = cx_Oracle.connect("cashpay", "cashpay", "10.164.200.241:1521/topccms")
	cursor = conn.cursor()
	cursor.execute(sql)
	conn.commit()
	conn.close()

query

def orace_query(sql):
	conn = cx_Oracle.connect("cashpay", "cashpay", "10.164.200.241:1521/topccms")
	cursor = conn.cursor()
	cursor.execute(sql)
	result = cursor.fetchall()
	cursor.close()
	conn.close()
	return result

Mysql

update / insert

def execute_query_sql(sql):
	host = "10.164.204.101"
	port = 3306
	db_user = "cmis"
	db_pwd = "cmis"
	db = "cmis_db"
	conn = pymysql.connect(host=host, port=port, user=db_user, passwd-db_pwd, db=db, use_unicode-True, charset="utf8")
	cursor = conn.cursor()
	cursor.execute(sql)
	conn.commit()
	cursor.close()
	conn.close()

query

def execute_query_sql(sql):
	host = "10.164.204.101"
	port = 3306
	db_user = "cmis"
	db_pwd = "cmis"
	db = "cmis_db"
	conn = pymysql.connect(host=host, port=port, user=db_user, passwd-db_pwd, db=db, use_unicode-True, charset="utf8")
	cursor = conn.cursor()
	cursor.execute(sql)
	db_data = cursor.fetchall()
	cursor.close()
	conn.close()
	return db_data

文章来源:https://blog.csdn.net/u013080870/article/details/135294142
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。