'''pycharm中第三方库的安装:http://www.cnblogs.com/duwangdan/p/6872750.html'''
-------------------------------------------连接数据库的代码------------------------------------------------------------------------
(代码的规范程度需要调整)
#!/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') #连接数据库
cursor=conn.cursor() #打开游标
sql= str #查询语句
try:
effect_row= cursor.execute(sql)# 执行查询
result=cursor.fetchall()# 打印所有查询结果
conn.commit()# 提交事务
exceptExceptionase :#要是发生错误
print(e)#打印错误原因
conn.rollback()#回滚事务
cursor.close()#关闭游标
conn.close()#关闭连接
returnresult#返回查询结果
'''pycharm中库的安装:http://www.cnblogs.com/duwangdan/p/6872750.html'''
print(psql_sjsg("select*from createrole limit 10"))