三分钟搞懂python_pymysql基本操作
下面讲讲关于python_pyMySQL基本操作,文字的奥妙在于贴近主题相关。所以,闲话就不谈了,我们直接看下文吧,相信看完python_pymysql基本操作这篇文章你一定会有所受益。
目前创新互联已为成百上千家的企业提供了网站建设、域名、虚拟空间、网站托管、服务器托管、企业网站设计、睢阳网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='mysql_test',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('test@python.org', 'test123!'))
# connection is not autocommit by default. So you must commit to save
# your changes.
connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `email`,`password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('test@python.org',))
result = cursor.fetchone()
print(result)
finally:
connection.close()
https://pypi.org/project/PyMySQL/#documentation
对于以上python_pymysql基本操作相关内容,大家还有什么不明白的地方吗?或者想要了解更多相关,可以继续关注我们的行业资讯板块。
当前题目:三分钟搞懂python_pymysql基本操作
文章来源:http://ybzwz.com/article/picsdg.html