您好,登錄后才能下訂單哦!
下面講講關于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基本操作相關內容,大家還有什么不明白的地方嗎?或者想要了解更多相關,可以繼續關注我們的行業資訊板塊。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。