开发者

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

I am trying to retrieve data in a sybase data base from python and I was wondering which would be the best way to d开发者_JS百科o it. I found this module but may be you have some other suggestions: http://python-sybase.sourceforge.net/ Thanks


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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜