国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看
打開APP
未登錄
開通VIP,暢享免費電子書等14項超值服
開通VIP
首頁
好書
留言交流
下載APP
聯(lián)系客服
python模塊之MySQLdb: 用python連接mysql數(shù)據(jù)庫
LibraryOfKevin
>《Python》
2011.12.05
關(guān)注
mysql是一個優(yōu)秀的開源數(shù)據(jù)庫,它現(xiàn)在的應(yīng)用非常的廣泛,因此很有必要簡單的介紹一下用python操作mysql數(shù)據(jù)庫的方法。python操作數(shù)據(jù)庫需要安裝一個第三方的模塊,在http://mysql-python.sourceforge.net/
有下載和文檔。
由于python的數(shù)據(jù)庫模塊有專門的數(shù)據(jù)庫模塊的規(guī)范,所以,其實不管使用哪種數(shù)據(jù)庫的方法都大同小異的,這里就給出一段示范的代碼:
#-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
# 連接數(shù)據(jù)庫
try:
conn = MySQLdb.connect(host='localhost',user='root',passwd='xxxx',db='test1')
except Exception, e:
print e
sys.exit()
# 獲取cursor對象來進行操作
cursor = conn.cursor()
# 創(chuàng)建表
sql ="create table if not exists test1(name varchar(128) primary key, age int(4))"
cursor.execute(sql)
# 插入數(shù)據(jù)
sql = "insert into test1(name, age) values ('%s', %d)"% ("zhaowei", 23)
try:
cursor.execute(sql)
except Exception, e:
print e
sql ="insert into test1(name, age) values ('%s', %d)"% ("張三", 21)
try:
cursor.execute(sql)
except Exception, e:
print e
# 插入多條
sql ="insert into test1(name, age) values (%s, %s)"val = (("李四", 24), ("王五", 25), ("洪六", 26))
try:
cursor.ex ......
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報
。
打開APP,閱讀全文并永久保存
查看更多類似文章
猜你喜歡
類似文章
Python操作mysql數(shù)據(jù)庫:MySQLdb模塊
[Python]MySQLdb for Python使用指南/Python的數(shù)據(jù)庫操作
python操作mysql數(shù)據(jù)庫 | 菜鳥教程
Python操作Mysql - 課程 - 從此學(xué)習(xí)網(wǎng)
Python使用MySQL數(shù)據(jù)庫的方法以及一個實例
Python MySQL
更多類似文章 >>
生活服務(wù)
首頁
萬象
文化
人生
生活
健康
教育
職場
理財
娛樂
藝術(shù)
上網(wǎng)
留言交流
回頂部
聯(lián)系我們
分享
收藏
點擊這里,查看已保存的文章
導(dǎo)長圖
關(guān)注
一鍵復(fù)制
下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!
聯(lián)系客服
微信登錄中...
請勿關(guān)閉此頁面
先別劃走!
送你5元優(yōu)惠券,購買VIP限時立減!
5
元
優(yōu)惠券
優(yōu)惠券還有
10:00
過期
馬上使用
×