Python 链接Mysql数据库
参考链接:https://pypi.python.org/pypi/PyMySQL#downloads
import pymysql.cursors,xml.dom.minidom
# Connect to the database
connection = pymysql.connect(host='192.168.75.134',
user='sdo',
password='51..sdo',
db='sdo_config',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
def checkGameTask(connection):
game_task_xml = open("gameTask_Check.xml",'w',encoding='utf-8')
impl = xml.dom.minidom.getDOMImplementation()
dom = impl.createDocument(None, 'RECORDS', None)
root = dom.documentElement
try:
with connection.cursor() as cursor:
sql = "SELECT `EventID`,`ScoreType`,`ScoreValue`,`TaskGate`,`TaskID`,`TaskState`,`TaskType`,`condExpr` FROM `gameTask`"
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
cfg = dom.createElement('RECORD')
cfg.setAttribute('TaskID','%s'%int(row.get('TaskID')))
cfg.setAttribute('TaskType','%s'%int(row.get('TaskType')))
cfg.setAttribute('EventID','%s'%int(row.get('EventID')))
cfg.setAttribute('condExpr','%s'%int(row.get('condExpr')))
cfg.setAttribute('TaskState','%s'%int(row.get('TaskState')))
cfg.setAttribute('TaskGate','%s'%int(row.get('TaskGate')))
cfg.setAttribute('ScoreType','%s'%int(row.get('ScoreType')))
cfg.setAttribute('ScoreValue','%s'%int(row.get('ScoreValue')))
root.appendChild(cfg)
dom.writexml(game_task_xml, addindent=' ', newl='\n')
finally:
connection.close() checkGameTask(connection)
Python 链接Mysql数据库的更多相关文章
- Django / Python 链接MySQL数据库
https://www.cnblogs.com/wupeiqi/articles/5237704.html python (Django)中使用MySQL 首先python3中没有 MySQLdb 需 ...
- Python --链接MYSQL数据库与简单操作 含SSH链接
项目是软硬件结合,在缺少设备的情况,需要通过接口来模拟实现与设备的交互,其中就需要通过从数据库读取商品的ID信息 出于安全考虑 现在很多数据库都不允许通过直接访问,大多数是通过SSH SSH : 数 ...
- python链接mysql数据库
1.安装pycharm python3.6 pip 在windows+R cmd where pip pip install mysql-client 如何看自已mysql-client有没有 ...
- Python学习笔记9-Python 链接MySql数据库
Python 链接MySql数据库,方法很简单: 首先需要先 安装一个MySql链接插件:MySQL-python-1.2.3.win-amd64-py2.7.exe 下载地址:http://dev. ...
- python链接mysql
1.安装MySQLdb MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的. 下载地址: ht ...
- python操作mysql数据库实现增删改查
Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: ...
- 【转】python操作mysql数据库
python操作mysql数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库 ...
- 转 Python 操作 MySQL 数据库
#########http://www.runoob.com/python/python-mysql.html Python 标准数据库接口为 Python DB-API,Python DB-API为 ...
- Python 操作MySQL 数据库
Python 操作 MySQL 数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的 ...
随机推荐
- node基础 --全局
全局对象: global:永远使用var 定义变量以避免引入全局变量; process:所有全局执行上下文的内容都在process对象中: 模块和包: 模块:一个Node.js 文件就是一个模块,这个 ...
- hadoop2.2.0部署
hadoop2.2.0部署 下载安装包 hadoop-2.2.0-cdh5.0.0-beta-1.tar.gz 解压 tar zxvf hadoop-2.2.0-cdh5.0.0-beta-1.tar ...
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- 【BZOJ】3781: 小B的询问(莫队算法)
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 还能不能再裸点.. #include <cstdio> #include < ...
- 深入理解JVM—性能监控工具
(转自:http://yhjhappy234.blog.163.com/blog/static/31632832201222691738865/) 我们知道,在JVM编译期和加载器,甚至运行期已经做了 ...
- Sqlserver 存储过程中结合事务的代码
Sqlserver 存储过程中结合事务的代码 --方式一 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ ...
- c++ <string.h>中包括哪些常用函数
常用函数如下:strlen 求字符串长度strcmp 比较2个字符串是否一样strcat 字符串连接操作strcpy 字符串拷贝操作strncat ...
- OpenSSL使用方法
生成CA (勾选Generate Self Signed Certificate)openssl req -nodes -x509 -sha256 -newkey rsa:4096 -keyout & ...
- PowerShell - Read an Excel file using COM Interface
http://www.lazywinadmin.com/2014/03/powershell-read-excel-file-using-com.html
- 使用安捷伦波形编辑软件产生GK101 任意波数据文件的方法(支持手绘)
软件安装包下载地址: 链接: http://pan.baidu.com/s/1bn8Lmhx 密码: v5xz 一.安捷伦IO套件安装 1.将压缩包解压,首先双击IOLibSuite_16_3_179 ...