python MySQLdb 参数化查询,pythonmysqldb,Python MySQL
python MySQLdb 参数化查询,pythonmysqldb,Python MySQL
Python MySQLdb 做参数化查询:
some_dictionary_with_the_data = { 'name': 'awesome song', 'artist': 'some band', etc...}cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (%(name)s, %(artist)s, %(album)s, %(genre)s, %(length)s, %(location)s) """, some_dictionary_with_the_data)
注意execute方法的第一个参数是一个格式化字符串,这个字符串的 %(name)s
是一个参数,这个参数的格式类似于python字符串的格式化,在(name)
中是第二个参数dict的key。
相关内容
- python判断字符串是否包含另一字符串的方法,python字符
- Find the global bounds on the eigenvalues of a tridiagomal matrix in
- python实现马耳可夫链算法,python马耳算法,import rando
- python通过Luhn算法验证信用卡卡号是否有效,pythonluhn,
- 【Python】diao丝娱乐(终极版)-->从百度贴吧下载妹子
- 糗百连连看,连连看,#!/usr/bin/p
- python, shell, golang获取本机IP地址,pythongolang,shell获取I
- 生成回文数,生成回文,生成10位以内的回文数不
- 输入地名获得当地天气预报,地名当地天气预报,#!/us
- python实现中文繁体和中文简体之间的相互转换,,# -*-
评论关闭