What is the best way to connect to a sybase database from python?

試著忘記壹切 提交于 2019-12-04 06:58:38

The sybase module you linked is by far the easiest way. You can get data like so:

import Sybase

db = Sybase.connect('server','name','pass','database')
c = db.cursor()
c.execute("sql statement")
list1 = c.fetchall()

print list1

You will have to use something like freetds to setup the interfaces for sybase, however.

you can also connect through ODBC.

There is also python-pymssql which is in Debian / Ubuntu. This can connect to MS-SQL-Server or Sybase using freetds. I'm not sure how it compares to the other options.

http://www.pymssql.org/

Example code, abridged from their website:

import pymssql

conn = pymssql.connect('server','user','pass','database')
cursor = conn.cursor()
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()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!