亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: python 連接 mysql 連接 sqlserver [打印本頁]

作者: longmm1988    時間: 2011-06-24 11:17
標題: python 連接 mysql 連接 sqlserver
Python連接 mysql  連接 sqlserver
安裝 python
Yum install python (相應ubuntu 用apt-get 千萬別一個包一個包自己裝 會死的很難看的 )
輸入python 出現(xiàn)如下界面表示 安裝成功。
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Ctrl+D 退出

安裝 python 與mysql的連接器 mysqldb
輸入 yum search mysqldb 出現(xiàn)如下信息
MySQL-python.i686
輸入 yum install MySQL-python
安裝 mysqldb成功。

測試文件 請看 utils 和 test1.py 如果不報錯則通過。。。

test1.py  
[root@localhost test]# cat test1.py
#!/usr/bin/python
#-*- coding: UTF-8 -*-
from utils import msutil

util=msutil.MSUtil()

con=util.getcon()
cur=con.cursor()
sql='select top 100 wname from ware where wid > %s and wpid=%d'
cur.execute(sql,('1110057019',80)

for row in cur:
  temp=row[0]
  flag=isinstance(temp, unicode)
     =temp.encode('utf8')
  print dd

cur.close()
con.close()

utils 包中 mysqlutil.py

[root@localhost utils]# cat mysqlutil.py
#!/usr/bin/python
#-*- coding: UTF-8 -*-
import MySQLdb

class MySQLdbUtil:

    def getCon():
        con=MySQLdb.connect(host='10.10.242.237' ,user='root' ,passwd='123456')
        con.select_db('python')
        return con
      



安裝 python 與sqlserver連接器 pymssql
輸入 yum search pymssql 出現(xiàn)如下信息
pymssql.i686 : A simple database interface to MS-SQL for Python
輸入 yum install pymssql
安裝成功
測試文件請看utils 如果不報錯 通過。。。。。(測試類暫無,與上面的mysql test1.py類似)

Utils 包中 msutil.py
[root@localhost utils]# cat msutil.py
#!/usr/bin/python
#-*- coding: UTF-8 -*-
import pymssql

class MSUtil:
  def __init__(self):
      print 'this ms util'
  def getCon(self):
     con = pymssql.connect(host='10.10.224.150',user='testwrite',password='654321',database='product',charset='gbk')
     return con
    # print   'getcon is diaoyong'
作者: longmm1988    時間: 2011-06-24 11:21
自己頂一下 呵呵
作者: longmm1988    時間: 2011-06-28 15:13
怎么沒有人頂呢?這是我對互聯(lián)網(wǎng)唯一的貢獻呀 。。。。
作者: longmm1988    時間: 2011-06-28 15:14
怎么沒人頂呢?? 這是我對互聯(lián)網(wǎng)唯一的貢獻呀。。。
作者: iamacnhero    時間: 2011-06-28 16:05
怎么沒人頂呢?? 這是我對互聯(lián)網(wǎng)唯一的貢獻呀。。。
longmm1988 發(fā)表于 2011-06-28 15:14


頂一下。
你要是編輯一下,代碼都用代碼格式,這樣就不會顯得編排很亂了。
作者: sjclovedz    時間: 2011-08-09 16:49
可能大家都懂吧
作者: 南國書生    時間: 2011-08-09 19:34
代碼質(zhì)量有待提高, 本來很簡單的, 整得這么凌亂。




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2