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

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

你可能感兴趣的:(数据库,python,oracle)