文章阅读 字体:
上一篇:
python 输出sql语句
日期:2014-06-26 17:43:12浏览:15次评论:作者:ylxhzjw
#!/usr/bin/env python #coding=utf-8import MySQLdb#建立和数据库系统的连接 conn = MySQLdb.connect(host='localhost', user='root',passwd='test')#选择数据库 conn.select_db('python');cursor.execute('set profiling = 1')#获取操作游标 cursor = conn.cursor()a=cursor.execute("""select * from test """)print aprint cursor.fetchall()try: cursor.execute('SELECT * FROM aaa where name = %s',[admin])except Exception: cursor.execute('show profiles') for row in cursor: print(row) cursor.execute('set profiling = 0')conn.close()
文章来源:
下一篇: