1. 程式人生 > 其它 >位元組跳動面試題

位元組跳動面試題

技術標籤:python

def save_mysql(title, date, source, content, tech_code, info_code):
    print(title, date, source, content, tech_code, info_code, 'jjjjjjjjjjjjj')
    db = pymysql.Connect(
        host='localhost',
        port=3306,
        user='root',
        passwd='123456',
        db='gc_test',
charset='utf8' ) cursor = db.cursor() sql = 'INSERT INTO information_stock (title,date,source,content,tech_code,info_code) VALUES ("%s","%s","%s","%s",%s,%s)' % ( title, date, source, content, tech_code, info_code) try: cursor.
execute(sql) db.commit() print("write success") except Exception as e: db.rollback() print("write fail") print(e) db.close()