当前位置:Gxlcms > 数据库问题 > Python 的 MySQLdb 模块

Python 的 MySQLdb 模块

时间:2021-07-01 10:21:17 帮助过:3人阅读

import MySQLdb

try:

    conn = MySQLdb.connect(host=‘‘,user=‘‘,passwd=‘‘,db=‘‘,port=)

    cur = conn.cursor()

    conn.select_db(‘db_name‘)

    value = [1,‘colben‘]

    cur.execute(‘insert into test values(%s,%s)‘,value)

    values = [(1,‘colben‘),(2,‘shelly‘)]

    cur.executemany(‘insert into test values(%s,%s)‘,values)

    cur.fetchall()

    cur.fetchmany(size)

    cur.fetchone()

    conn.commit()

    conn.rollback()

    cur.close()

    conn.close()

except MySQLdb.Error,e:

    print ‘Mysql Error %d: %s‘%(e.args[0], e.args[1])


Python 的 MySQLdb 模块

标签:

人气教程排行