Hi. I have read this http://www.yiiframew…pic,2347.0.html but is it possible to use two or more databases AND a single connection?
The databases are of course on the same server, same credentials.
Hi. I have read this http://www.yiiframew…pic,2347.0.html but is it possible to use two or more databases AND a single connection?
The databases are of course on the same server, same credentials.
I think this topic is out of Yii's scope as a web framework, you should google on it.
AFAIK, it's possible to have multiple DB on SAME server for Mysql, not sure other RDBMS
I am no aware of any solution for a sqlite database. I agree with Will, it is beyond Yii’s scope although we know Qiang is genious enough to have a solution for most computer problems related to php.
If you are using MySQL, you can use multiple DBs with the same connection. The reason is because MySQL treats a database as a schema. And you can prefix your table names with database names. For example, you can do "SELECT * FROM db2.table1" even if you are connecting to MySQL using database 'db1'.
Maybe this is beyond Yii's scope, but I definitely thinks its on topic, ie trying to make your setup work with Yii.
I wonder about the MySQL part where, like you say, we can easy access different databases through the same connection. I know the way to do it via SQL, but
how and where would one implement this in the Models etc?
For example: i have two tables (t1, t2) in two databases (d1, d2). Should i do like in the other forumpost, and add another db to the config, or is there a way to do make a new extended class that does something like a mysql_select_db. The latter would seem to me like an elegant solution?
I would think that if you set the tableName() method to return the database name along with the table name, this will cover your butt in the model setup, no?
/** * @return string the associated database table name */ public function tableName() { return 'db1.table_name'; }
Than certainly looks like an elegant solution, thanks!
I'm all about the elegance…