PythonでMySQLとMSSQLを接続する

サンプルコード:

host = '127.0.0.1’
user = 'pythonadmin’
pwd = 'startnews24’
dbname = startnews24_testdb"
conn_my, conn_ms = None, None
import MySQLdb
conn_my = MySQLdb.connect(host=host,
user=user,passwd=pwd, db=dbname, connect_timeout=5)

import pymssql
conn_ms = pymssql.connect(host=host,
user=user,password=pwd, database=dbname)
if conn_my:
print 'conn mysql:’, conn_my.ping(),
cursor = conn_my.cursor()
cursor.execute('select LENGTH(“sql")’)
data = cursor.fetchall()
print data
if conn_ms:
print 'conn mssql:’, conn_ms.ping(),
cursor = conn_ms.cursor()
cursor.execute('select LENGTH(“sql")’)
data = cursor.fetchall()
print data

Development

Posted by arkgame