网站制作学习网Python→正文:python mysql 判断更新成功
字体:

python mysql 判断更新成功

Python 2022/2/9 18:42:28  点击:不统计


 python mysql 判断更新成功

直接上代码
class A
#数据库连接部分
 def server_connection(self):

    try:

        self.server_db.ping()

    except:

        self.server_db = pymysql.connect(host=self.server_config['host'],

                                         user=self.server_config['user'],

                                         passwd=self.server_config['passwd'],

                                         db=self.server_config['dbname'],

                                         port=self.server_config['port'],

                                         charset='utf8mb4')

    return self.server_db
#更新数据库部分

def update_book_desc(self, bookid, desc):

    sql = "update book set title=‘adsf’ where id = 1"

    cursor = self.local_connection().cursor()

    cursor.execute(sql)

    self.test_connection().commit()

    if cursor.rowcount > 0:

        print("更新简介成功 图书ID", bookid)

    else:

        print("更新图书简介失败  图书ID", bookid)

    pass


 


·上一篇:scrapy response >>    ·下一篇:python 安装 execjs >>
推荐文章
最新文章