文件型数据库sqllite读写操作:
def ExecSql(dbFileName,stats): """ | [email protected]: 执行sqlite语句 | [email protected]: | [email protected]: sqlite数据库查询结果 | [email protected]: | [email protected]:本函数只适用于查询sqlite数据库 """ con = sqlite3.connect(dbFileName) cur = con.cursor() stats = stats.decode("gbk") cur.execute(stats) con.commit() DBExecResult = cur.fetchall() con.close() return DBExecResult
MySQL数据库读写操作:
def ExecSql(sql, dbName="", host="", user="", passwd="", charset=''): import MySQLdb conn = MySQLdb.connect(host=host, user=user, passwd=passwd, charset=charset) conn.select_db(dbName) cursor = conn.cursor() cursor.execute(sql) conn.commit() result = cursor.fetchall() cursor.close() conn.close() return result
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8173.html