본문 바로가기
기술자료/DB

초간단 소스 MS-SQL Driver Connect Adapter Test python Database

by 와이즈캣 2021. 10. 6.
728x90
반응형

============================================================

import pymssql

Ip      = '192.168.0.146'
Port    = '1433'
DB      = 'ShopDB'
ID      = 'Wowcat'
PW      = 'cocoon115'

conn = pymssql.connect(
        server=Ip,
        database=DB,
        user=ID,
        password=PW
        )
cursor = conn.cursor()

cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
    print(row[0])
    row = cursor.fetchone()


============================================================


============================================================

import pymssql

Ip      = '192.168.0.146'
Port    = '1433'
DB      = 'ShopDB'
ID      = 'Wowcat'
PW      = 'cocoon115'

conn = pymssql.connect(
        server=Ip,
        database=DB,
        user=ID,
        password=PW
        )
cursor = conn.cursor()

cursor.execute("SELECT * FROM memberTBL;")
row = cursor.fetchone()
while row:
    print(row)
    row = cursor.fetchone()


============================================================

============================================================

import pymssql

Ip      = '192.168.0.146'
Port    = '1433'
DB      = 'ShopDB'
ID      = 'sa'
PW      = '1'

conn = pymssql.connect(
        server=Ip,
        database=DB,
        user=ID,
        password=PW
        )
cursor = conn.cursor()
querySelect = "SELECT * FROM memberTBL;"
#queryInsert = "INSERT INTO memberTBL VALUES('Han1','한가람','부산시 금정구');"
#cursor.execute(queryInsert)
#conn.commit()

cursor.execute(querySelect)
row = cursor.fetchone()
while row:
    print(row)
    row = cursor.fetchone()


============================================================

728x90