溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

三分鐘搞懂python_pymysql基本操作

發(fā)布時間:2020-05-22 17:12:55 來源:網(wǎng)絡 閱讀:193 作者:三月 欄目:編程語言

下面講講關于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基本操作相關內容,大家還有什么不明白的地方嗎?或者想要了解更多相關,可以繼續(xù)關注我們的行業(yè)資訊板塊。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI