????python ????????????????Python????????????MySQL-python-1.2.2.win32-py2.5.exe???????????????MySQLdb????????????????????
???????????????£?
????1???????????????
????import MySQLdb
????conn=MySQLdb.connect(host="localhost"??user="root"??passwd="sa"??db="mytable")
????cursor=conn.cursor()
????2?????????????
????n=cursor.execute(sql??param)
????????????????????????cursor????????????????????cursor????????????й???.
??????Щ??????????????:1.???????2.????????
????cursor???????????????:
????callproc(self?? procname?? args):??????д洢???????????????洢????????????б??????????????????
????execute(self?? query?? args):??е???sql????????????sql??????????????б??????????????????
????executemany(self?? query?? args):??е???sql????????????в????б?????????????????????????
????nextset(self):???????????????
????cursor?????????????????:
????fetchall(self):????????????????.
????fetchmany(self?? size=None):????size??????????.???size??????????????е????????????cursor.arraysize??????.
????fetchone(self):????????????.
????scroll(self?? value?? mode='relative'):??????????.???mode='relative'???????????????????value???????mode='absolute'???????????????? ?????value??.
???????????????????????????.
????#???sql????????????????????%s?λ??.??????????????????????????????????λ??????????%s
????sql="insert into cdinfo values(%s??%s??%s??%s??%s)"
????#param????tuple????list
????param=(title??singer??imgurl??url??alpha)
????#??У?????????n????1
????n=cursor.execute(sql??param)
????#??????????????????
????cursor.execute("select * from cdinfo")
????#?????????fetchall???????.??????cds???????????????????????.?????????????tuple????????????Щtuple????????tuple
????cds=cursor.fetchall()
????#?????tuple???????????????y????
????print cds[0][3]
????#??????????????????????????????????
????print cds
????#??????????????????????????
????sql="insert into cdinfo values(0??%s??%s??%s??%s??%s)"
????#?????????????tuple??????????????????tuple??????list
????param=((title??singer??imgurl??url??alpha)??(title2??singer2??imgurl2??url2??alpha2))
????#???executemany???????????????????.????????????????!
????n=cursor.executemany(sql??param)
?????????????(?????????е???????)????????????????????????????????????conn.commit()??????????.?????????????????? ???????????.??????????????mysql???????????????????????????????????commit?????????????????????У?????????? ???????????.??????????????????????????????????????????0.
????3.????????????
???????????????????????????.??????????????????
????cursor.close()
????conn.close()
????Django?????????
????django??????????????python??web????django?????в?????????api????????????????????settings.py?????ú???????????????????modules??view??urls?з??д????????