pymssqlPython 数据库接口
一个简单的 Python 数据库接口,它建立在 FreeTDS 之上,为 Microsoft SQL Server 提供 Python DB-API(PEP-249)接口。
示例代码:
import pymssql conn = pymssql.connect(host='SQL01', user='user', password='password', database='mydatabase') cur = conn.cursor() cur.execute('CREATE TABLE persons(id INT, name VARCHAR(100))') cur.executemany("INSERT INTO persons VALUES(%d, %s)", \ [ (1, 'John Doe'), (2, 'Jane Doe') ]) conn.commit() cur.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe') row = cur.fetchone() while row: print "ID=%d, Name=%s" % (row[0], row[1]) row = cur.fetchone() conn.close()
评论