python連線mongodb查詢:
deffech_mongo(data):
host = data.pop("
host")
port = int(data.pop("
port"))
db_name = data.pop("
db_name")
batch_no = data.pop("
batch_no")
(host,port,db_name,batch_no,data)
message = ''
for field in
data.keys():
client =pymongo.mongoclient(host, port)
db =client[db_name]
table_name = field.split("."
)[0]
key = field.split("
.")[1]
collection_set =db[table_name]
try:
value = collection_set.find_one()[key]
if value !=data[field]:
message += field+"
"+data[field]+"
不等於"+value+","
except
exception:
logger.exception('')
return message
python連線sqlserver查詢
deffethdata():
host = '
10.138.**。**
'user = 'sa'
password = '
f******93
'database = '
po******n
'conn = pymssql.connect(host=host, user=user, password=password, database=database, charset='
utf8')
cursor =conn.cursor()
cursor.execute(
'select top 1 businessid from business')
results =cursor.fetchall()
conn.close()
print(results)
注意:charset='utf8'
參考:python連線oracle
1.安裝cx_oracle版本:cx_oracle-5.3-11g.win-amd64-py3.4.exe(注意與python版本匹配)
不建議直接使用pip install cx_oracle命令安裝
2.安裝oracle客戶端:instantclient-basic-windows.x64-11.2.0.4.0.zip(注意版本和位數與python匹配)
3.python連線oracle資料指令碼
importosos.environ[
'nls_lang
'] = '
simplified chinese_china.utf8'#
os.environ['path'] = 'd:\oracle\instantclient_11_2'
import
cx_oracle
if__name__ == '
__main__':
str = '
vcs_prod/[email protected]/orcl
'conn =cx_oracle.connect(str)
sql = "
select * from m_contact_info where business_id = '304815'
"cr =conn.cursor()
cr.execute(sql)
data =cr.fetchall()
print(data)
參考:
python 連線資料庫
原文 原文1 安裝mysql python pip install mysql python dome1 def db mange db bank conn none try 開啟資料庫連線 conn mysqldb.connect localhost root 123456 db bank 獲取操...
Python連線資料庫
usr bin env python coding utf 8 import sys reload sys sys.setdefaultencoding utf 8 import pymysql import pymysql.cursors usr bin env python coding utf...
python連線資料庫
1 安裝mysql ubantu下安裝不撰述 2 安裝python版本的mysql開發包 sudo apt get install python mysqldb3 編寫python usr bin python coding utf 8 import mysqldb 引入mysqldb包 開啟資料庫...