import pymysql
def createConnection():
db = pymysql.Connect(
host='127.0.0.1',
port=3306,
user='root',
passwd='root',
db='mydbdemo',
charset='utf8'
)
return db
def executeSelectONEback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
dataone = cursor.fetchone()
return dataone
except:
return False
finally:
db.close()
def executeSelectAllback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
dataall = cursor.fetchall()
return dataall
except:
return False
finally:
db.close()
def executeInsertIDback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
db.commit()
the_id = int(cursor.lastrowid)
return the_id
except:
db.rollback()
return False
finally:
db.close()
def executeUpdateNOback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
db.commit()
return True
except:
db.rollback()
return False
finally:
db.close()
def executeDeleteNOback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
db.commit()
return True
except:
db.rollback()
return False
finally:
db.close()
def executeCreateNOback(sqlstring):
try:
db = createConnection()
cursor = db.cursor()
cursor.execute(sqlstring)
return True
except:
db.rollback()
return False
finally:
db.close()
打开App,阅读手记