第一节、Alex 讲解 python+mysql 交互;
生活随笔
收集整理的這篇文章主要介紹了
第一节、Alex 讲解 python+mysql 交互;
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Python Mysql 交互
A、Alex 的語(yǔ)法展示:import MySQLdb?try:conn=MySQL.connect(host='localhost',user='root',passwod='123qwe',db='test-DB',port='3306')cur?=conn.cursor()cur.execute('select * from user_info')? ? ?cur.close()? ? ?conn.close()except MySQLdb.Errot,e:? ? ?print 'Mysql Error ?Msg:' , e?B、例子:例子1、獲取數(shù)據(jù)
2、插去數(shù)據(jù);
常用函數(shù):注意這個(gè) commit( ) 提交rollback( ) 回滾
(二)、插去多條數(shù)據(jù)。
查詢數(shù)據(jù)庫(kù)的結(jié)果:
例子展示:
釋義:cur.scroll(3,mode="relative") ? # ?光標(biāo)相對(duì)的移動(dòng)到 第三行;cur.scroll(0,mode='absolute') ?print cur.fetchone ( ) ? ? ? ? ? ? ? ?# ?取一行內(nèi)容;從當(dāng)前游標(biāo)處。print cur.fetchall( ) ? ? ? ? ? ? ? ? ? ?#從當(dāng)前位置取全部的行;ps: 默認(rèn)的 是從 0行開(kāi)始的, ??
執(zhí)行結(jié)果后:
來(lái)自為知筆記(Wiz)
轉(zhuǎn)載于:https://www.cnblogs.com/zhangju/p/5720211.html
總結(jié)
以上是生活随笔為你收集整理的第一节、Alex 讲解 python+mysql 交互;的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: wamp httpd-vhosts.co
- 下一篇: UVA 12219-Common Sub