官术网_书友最值得收藏!

Multiple database connections

In MySQL for Python, all database objects are discrete. All you need do is to connect with each under a different name. Consider the following:

mydb1 = MySQLdb.connect(host="localhost", 
                        user="skipper", 
                        passwd="mysecret", 
                        db="fish")
mydb2 = MySQLdb.connect(host="localhost", 
                        user="skipper", 
                        passwd="mysecret", 
                        db="fruit")
cursor1 = mydb1.cursor()
cursor2 = mydb2.cursor()

The objects then function like any other variable or object. By calling their methods and attributes separately, you can interact with either or even copy from one to the other.

主站蜘蛛池模板: 达拉特旗| 石景山区| 集安市| 遂昌县| 板桥市| 招远市| 弥渡县| 涿州市| 长岛县| 潜江市| 额敏县| 依安县| 上栗县| 双峰县| 壤塘县| 日土县| 嘉峪关市| 永清县| 太原市| 深州市| 平泉县| 乌海市| 平凉市| 屏边| 弋阳县| 郑州市| 平湖市| 高陵县| 泗水县| 庆云县| 仪征市| 迁西县| 巴里| 开原市| 庆元县| 三江| 邵东县| 三明市| 海晏县| 华宁县| 镇平县|