SQL基本語法 - Python版:

db = MySQLdb.connect(host="localhost", user="root", passwd="5796857968", db="OVS")

cursor = db.cursor()#Create instance to access DB

 

1. update

     cursor.execute("update OVS.check_cv_Info set  packets_now=%s,status=%s where subnet=%s and subnet_section=%s", [ n_packets[i], "1" ,db_value[j][0] ,db_value[j][1] ] )
db.commit()

 

2. select

cursor.execute("SELECT packets_now From check_cv_Info WHERE subnet=%s", [ get_subnet[i] ]) #15
packets_rownu = cursor.rowcount #rows number
packets = cursor.fetchall()

 

 3. insert

cursor.execute("INSERT INTO Pica8_Switch_Help(FK, Help_Nu) VALUES(%s,%s)", [ str( int(j)+1 ), str( int(dead_switch[i])+1 ) ] ) #Update to DB, +1 in order to 'Nu' field
db.commit()

 

4. delete

cursor.execute("DELETE FROM OVS.check_cv_Info")
db.commit()

 

文章標籤
全站熱搜
創作者介紹
創作者 Wayne 的頭像
Wayne

Wayne Technique Study

Wayne 發表在 痞客邦 留言(0) 人氣(2,296)