1133 _databases = {}1134 def database(dburl=None, **params):1135 """Creates appropriate database using params.1136 1137 Pooling will be enabled if DBUtils module is available. 1138 Pooling can be disabled by passing pooling=False in params.1139 """1140 dbn = params.pop("dbn")1141 if dbn in _databases:1142 return _databases[dbn](**params)1143 else:1144 raise UnknownDB, dbn可以看出的是,dburl的確沒有起到作用,註釋裡面也說了: Creates appropriate database using params。不過一般連線mysql資料庫透過以下引數連線的話,應該是可以連線上的吧。(我沒有試過遠端,所以不敢肯定。)import webdb = db.database( dbn="mysql", db="dbname", host="host", port=3306, user="user", pw="password")
看了web.py原始碼,關於連線資料庫的函式如下(webpy/web/db.py):
1133 _databases = {}1134 def database(dburl=None, **params):1135 """Creates appropriate database using params.1136 1137 Pooling will be enabled if DBUtils module is available. 1138 Pooling can be disabled by passing pooling=False in params.1139 """1140 dbn = params.pop("dbn")1141 if dbn in _databases:1142 return _databases[dbn](**params)1143 else:1144 raise UnknownDB, dbn可以看出的是,dburl的確沒有起到作用,註釋裡面也說了: Creates appropriate database using params。不過一般連線mysql資料庫透過以下引數連線的話,應該是可以連線上的吧。(我沒有試過遠端,所以不敢肯定。)import webdb = db.database( dbn="mysql", db="dbname", host="host", port=3306, user="user", pw="password")