美文网首页
pymysql连接数据库

pymysql连接数据库

作者: peng_js | 来源:发表于2017-06-30 12:58 被阅读0次

    import pymysql

    #链接数据库

    conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='bookapi', charset='utf8')

    #设置浮标

    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    sel='select count(*) from bi_book where isbn ='+isbn

    cursor.execute(sel)

    result=cursor.fetchone()

    count=result['count(*)']

    if count != 0 :

    return 'back'

    #要插入的列表

    li=[0,source_type,category,details,detail_url,price,add_time,packaging,print_time,impressions,name,author,press_name,isbn,edition,size,press_time,page_num,word_num,img_big,img_small]

    #执行sql

    sql="insert into bi_book (book_id,source_type,category,details,detail_url,price,add_time,packaging,print_time,impressions,name,author,press_name,isbn,edition,size,press_time,page_num,word_num,img_big,img_small) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"

    aaa=cursor.execute(sql,li)

    conn.commit()

    相关文章

      网友评论

          本文标题:pymysql连接数据库

          本文链接:https://www.haomeiwen.com/subject/ttgbcxtx.html