码迷,mamicode.com
首页 > 数据库 > 详细

linux下安装pymssql

时间:2016-08-22 10:42:38      阅读:760      评论:0      收藏:0      [点我收藏+]

标签:

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=utf8, port=1433, 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()

 

linux下安装pymssql

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5794598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!