win 下python2.7 pymssql连接ms sqlserver 2000
2014-02-08 01:07
483 查看
python DB-API 连接mysql 要用到库pymssql 下载请到https://pypi.python.org/pypi/pymssql/2.0.1我这里下载的是ms windows installer版本exe文件,直接运行就可以了,whl和egg格式的看不懂怎么安装.
下载完,试着连接到本机的pubwin数据库写了一句查询,很方便的样子
con=pymssql.connect(host='.',user='sa',password='sa',database='local'),百度了一下,python DB-API连接数据库都是用这个格式标准。host可以用ip:1433的格式 带端口。
fetchall():用来取回cur的所有数据,fetchone 是只取回一行数据,上面的查询,同样可以用detchone实现:
参考:http://tech.it168.com/a2009/1014/759/000000759444.shtml(利用MySQLdb 对DB-API的详细介绍,推荐)
下载完,试着连接到本机的pubwin数据库写了一句查询,很方便的样子
# -*- coding:gbk -*- import pymssql try: con=pymssql.connect(host='.',user='sa',password='sa',database='local') cur=con.cursor() cur.execute('select uniqueid,levelid from mem_localmemberbaseinfo') for uniqueid,levelid in cur.fetchall(): print 'uniqueid: %s,levelid: %s' % (uniqueid,levelid) print cur.rowcount cur.close() con.close() except: print 'sql Error'
con=pymssql.connect(host='.',user='sa',password='sa',database='local'),百度了一下,python DB-API连接数据库都是用这个格式标准。host可以用ip:1433的格式 带端口。
fetchall():用来取回cur的所有数据,fetchone 是只取回一行数据,上面的查询,同样可以用detchone实现:
# -*- coding:gbk -*- import pymssql try: con=pymssql.connect(host='127.0.0.1:1433',user='sa',password='sa',database='local') cur=con.cursor() cur.execute('select uniqueid,levelid from mem_localmemberbaseinfo order by uniqueid') rowcount=0 while 1: row=cur.fetchone() if row==None:break print "uniqueid: %s,levelid %s" % (row[0],row[1]) rowcount+=1 print rowcount cur.close() con.close() except: print 'sql Error'
参考:http://tech.it168.com/a2009/1014/759/000000759444.shtml(利用MySQLdb 对DB-API的详细介绍,推荐)
相关文章推荐
- Issue 71 - pymssql - Undefined symbols on Mac, CentOS, Redhat with pre-compiled build - A fast MS SQL Server client library for Python directly using C API instead of ODBC. It is Python DB-API 2.0 compliant. Works on Linux, *BSD, Solaris, Mac OS X and Win
- 连接远程ms sql server 2000企业版时出现错误:10061的解决方法
- 利用JDBC连接MS SQL Server 2000 + sp2
- 连接远程ms sql server 2000企业版时出现错误:10061的解决方法
- Python连接SQL Server数据库 - pymssql使用基础
- 使用MyEclipse7.5连接MS SQL Server 2000
- 安装、连接MS SQL Server 2000的问题
- 水晶报表连接MS-SQL-Server 2000的经验总结
- Oracle SQL Developer连接MS SQL SERVER 2000的配置步骤
- brio 连接MS sql server 2000 与analysis service(转)
- Oracle SQL Developer连接MS SQL SERVER 2000的处理
- jdbc连接ms sqlserver 2000问题汇总
- 深入探索MS SQL Server 2000网络连接的安全问题
- Oracle SQL Developer连接MS SQL SERVER 2000的处理
- linux下使用Freetds 连接MS SqlServer 2000 (C语言实现)
- jBuilder2005和MS SQL Server 2000连接
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- brio 连接MS sql server 2000
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- 连接远程ms sql server 2000企业版时出现错误:10061的解决方法