zoukankan      html  css  js  c++  java
  • python3 连接SQLserver

    pymssql 是Python语言用来连接微软 SQL SERVER 数据库的类库,实现了 Python DB API 2.0 。官网介绍

    安装包:

    (python34) C:WINDOWSsystem32> pip install  pymssql
    Collecting pymssql
      Downloading pymssql-2.1.3-cp34-cp34m-win_amd64.whl (371kB)
        100% |████████████████████████████████| 378kB 525kB/s
    Installing collected packages: pymssql
    Successfully installed pymssql-2.1.3
    
    (python34) C:WINDOWSsystem32>
    (python34) C:WINDOWSsystem32>
    (python34) C:WINDOWSsystem32> pip install  pymysql
    Collecting pymysql
      Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
        100% |████████████████████████████████| 81kB 155kB/s
    Installing collected packages: pymysql
    Successfully installed pymysql-0.7.11

    最简事例:

    #!/usr/bin/env python
    # encoding: utf-8
    """
    @author: 侠之大者kamil
    @file: sqlserver.py
    @time: 2016/5/31 9:08
    """
    import pymssql
    conn = pymssql.connect(host="10.x.x.1x2CRM_MY",user="scxxx",password="xxxx!@#",database="myerp_main_v5",charset="utf8")
    cur = conn.cursor()
    if not cur:
        raise (NameError,"数据库连接失败")
    cur.execute("SELECT top 30 * from p_Customer")
    resList = cur.fetchall()#fetchall()是接收全部的返回结果行
    conn.close()
    print(resList)

      

      

    公众号请关注:侠之大者
  • 相关阅读:
    男子头部胀痛案
    摩这些穴位可以对付突发的疾病
    跟师学习时的几个经验方
    黄褐斑良方--- 疏肺散斑汤
    食积咳嗽的特点
    牙痛用药口决(来源于网络暂未验证)
    20多年脚气起泡脱皮瘙痒外洗方治验案
    起死回生通关散
    腰突辩治心得(付济华)
    战痘良方--付济华
  • 原文地址:https://www.cnblogs.com/kamil/p/5544952.html
Copyright © 2011-2022 走看看