MySQLdb数据库操作
来源:互联网 发布:mac上打开隐藏文件夹 编辑:程序博客网 时间:2024/05/19 23:16
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb
# 打开数据连接
db = MySQLdb.connect('localhost', 'root', '', 'test')
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用 execute() 执行sql语句
username = 'wood444'
sex = 4
sql = """INSERT INTO test(name,sex) VALUES ('%s', '%d')""" % (username, sex)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
print "insert error!"
db.close()
# -*- coding: UTF-8 -*-
import MySQLdb
# 打开数据连接
db = MySQLdb.connect('localhost', 'root', '', 'test')
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用 execute() 执行sql语句
username = 'wood444'
sex = 4
sql = """INSERT INTO test(name,sex) VALUES ('%s', '%d')""" % (username, sex)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
print "insert error!"
db.close()
0 0
- MySQLdb数据库操作
- Python MYSQLdb操作数据库
- MySQLdb和Python数据库操作
- python使用MySQLdb操作数据库
- python操作MySQL数据库(MySQLdb
- python数据库操作 - PyMySQL,MySQLdb
- MySQLdb:Python 操作 MySQL 数据库
- python 通过mysqldb 操作mysql数据库
- 【python系列】mysqldb模块操作数据库
- python操作数据库模板 MySQLdb模块
- python 用mysqldb方式操作数据库
- python MySQLdb API的数据库更新操作
- 【MySQLdb模块】Python操作MySQL数据库
- python利用MySQLdb操作远程数据库
- python数据库操作模块MySQLdb简介
- python下使用MySQLdb操作MYSQL数据库
- MySQLdb for Python使用指南/Python的数据库操作
- MySQLdb for Python使用指南/Python的数据库操作
- java项目中logger一般使用 static final
- CodeForces 316D3 PE Lesson [DP+Math]
- This is an A+B Problem
- 总结iOS 多线程学习过程五
- MySQL show processlist 中status
- MySQLdb数据库操作
- 传纸条
- 【问题】Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds
- 《iOS Human Interface Guidelines》——Integrating with iOS
- fiddler post 二进制数据
- [POJ 2778] DNA Sequence (AC自动机+DP+矩阵加速)
- apt-get update 失败
- Find the Duplicate Number
- iOS NSURLConnection