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

  • MySQL for Python
  • Albert Lukaszewski, PhD
  • 76字
  • 2021-04-13 17:12:27

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.

主站蜘蛛池模板: 开化县| 建德市| 北海市| 民勤县| 瓮安县| 宁都县| 洪江市| 浦东新区| 通化县| 房山区| 自治县| 璧山县| 荣成市| 抚顺县| 呈贡县| 凤凰县| 泊头市| 恩平市| 来安县| 隆德县| 临江市| 垦利县| 定边县| 盘山县| 林州市| 道孚县| 房产| 新野县| 商洛市| 浙江省| 长兴县| 信丰县| 潢川县| 华安县| 台山市| 神木县| 保山市| 高雄市| 汪清县| 广灵县| 保德县|