WIN下安装PYMSSQL,由于我没有系统管理权限,无法安装,

那只好在LINUX下面安装罗。。

以下这个文章帮助我搞定。

http://blog.csdn.net/five3/article/details/16338191

各版本的下载地址:https://pypi.python.org/pypi/pymssql/

Windows可以下载installer文件,直接是编译好的,可以直接安装

Linux下需要安装几个基础类库:

Cpython:pip install Cpython        ##Python

freetds-dev:yum install freetds-devel.x86_64 / apt-get install freetds-dev   ##linux包

最后安装pymssql: pip install pymssql

import pymssql
conn = pymssql.connect(host=host, user=user, password=password,
        database=database, charset=', as_dict=False)
cursor = conn.cursor()
sql = "select * from payment where id in (59,60)"
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
    print row
from os import getenv
import pymssql

server = getenv("PYMSSQL_TEST_SERVER")
user = getenv("PYMSSQL_TEST_USERNAME")
password = getenv("PYMSSQL_TEST_PASSWORD")

conn = pymssql.connect(server, user, password, "tempdb")
cursor = conn.cursor()
cursor.execute("""
IF OBJECT_ID('persons', 'U') IS NOT NULL
    DROP TABLE persons
CREATE TABLE persons (
    id INT NOT NULL,
    name VARCHAR(100),
    salesrep VARCHAR(100),
    PRIMARY KEY(id)
)
""")
cursor.executemany(
    "INSERT INTO persons VALUES (%d, %s, %s)",
    [(1, 'John Smith', 'John Doe'),
     (2, 'Jane Doe', 'Joe Dog'),
     (3, 'Mike T.', 'Sarah H.')])
# you must call commit() to persist your data if you don't set autocommit to True
conn.commit()

cursor.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe')
row = cursor.fetchone()
while row:
    print("ID=%d, Name=%s" % (row[0], row[1]))
    row = cursor.fetchone()

conn.close()

最新文章

  1. UVa 307 - Sticks
  2. ASP.NET中常用重置数据的方法
  3. Python之路【第十篇】:HTML -暂无等待更新
  4. Permutations,Permutations II,Combinations
  5. rsyslog 日志服务器端配置
  6. 基于Xcode8插件开发~一键检测处理头文件引用
  7. .opt,frm,.MYD,.MYI文件如何转为.sql文件?
  8. 赋给个人账户sudo的全部root执行权限
  9. Tarjan + bfs HYSBZ 1179Atm
  10. Angular6 Observable.fromEvent error: “Invalid event target”
  11. win7文件搜索技巧
  12. IntelliJ IDEA web项目 工程构建运行部署
  13. httpd基础知识
  14. 《Linux内核设计与实现》读书笔记 4 进程调度
  15. 洛谷P1600 天天爱跑步
  16. [Python设计模式] 第3~5章 单一职责原则/开放-封闭原则/依赖倒转原则
  17. Java8新特性之Stream
  18. Slickflow.NET 开源工作流引擎高级开发(二) -- 流程快速测试增值服务工具介绍
  19. webGl中实现clipplane
  20. 联通GWH-01路由猫超级用户登录方法

热门文章

  1. ECSHOP用户协议字体颜色更改
  2. easyui datagrid 通过复选框删除新追加的数据问题
  3. try catch finally执行顺序
  4. IE浏览器模式设置
  5. 用C语言画一个“爱心”
  6. 【整理】Angularjs 监听ng-repeat onfinishrender事件
  7. MATLAB对话框设计[转]
  8. meta中的viewport指令
  9. 繁华模拟赛 Vicent坐电梯
  10. POJ 3274 Gold Balanced Lineup