'''pycharm中第三方庫的安裝:http://www.cnblogs.com/duwangdan/p/6872750.html'''

-------------------------------------------連接數(shù)據(jù)庫的代碼------------------------------------------------------------------------
(代碼的規(guī)范程度需要調(diào)整)
#!/usr/bin/env pytho
# -*- coding:utf-8 -*-
defpsql_sjsg (str):
importpymysql
conn = pymysql.connect(host='120.132.67.103',
port=3306,
user='UserSelect',
passwd='1q2w3e4r5t',
db='bingosjsg',
charset='utf8') ? ? ? ?#連接數(shù)據(jù)庫
cursor=conn.cursor() ? ? ? ? #打開游標(biāo)
sql= str ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查詢語句
try:
? ? effect_row= cursor.execute(sql)# 執(zhí)行查詢
? ? result=cursor.fetchall()# 打印所有查詢結(jié)果
? ? conn.commit()# 提交事務(wù)
exceptExceptionase :#要是發(fā)生錯(cuò)誤
? ? print(e)#打印錯(cuò)誤原因
? ? conn.rollback()#回滾事務(wù)
cursor.close()#關(guān)閉游標(biāo)
conn.close()#關(guān)閉連接
returnresult#返回查詢結(jié)果
'''pycharm中庫的安裝:http://www.cnblogs.com/duwangdan/p/6872750.html'''
print(psql_sjsg("select*from? createrole limit 10"))