代码:
#!/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb # 连接数据库 db = MySQLdb.connect("1.1.1.1","user01","@@@","xatest" ) cursor = db.cursor() # SQL sql = "SELECT * FROM wp_posts WHERE post_author =1" try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() except: db.rollback() data = cursor.fetchall() for row in data: ID = row[0] author = row[1] postdate = row[2] content = row[4] title = row[5] print("ID是:{}n作者:{}n发布日期:{}n标题:{}n内容是:{}n ".format(ID,author,postdate,title,content)) db.close()