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

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.

主站蜘蛛池模板: 台北县| 海林市| 绥棱县| 屯留县| 毕节市| 石家庄市| 盘锦市| 综艺| 青冈县| 阜新市| 鄂托克前旗| 汽车| 东源县| 德昌县| 赤水市| 上思县| 全椒县| 夏邑县| 东台市| 准格尔旗| 依安县| 托克托县| 香港| 饶阳县| 饶阳县| 项城市| 上虞市| 平罗县| 昌图县| 鹤峰县| 正蓝旗| 兴国县| 阜新| 分宜县| 桃园县| 朔州市| 三河市| 卓资县| 鄄城县| 尼玛县| 阿勒泰市|