<<-multiple database->>you can manage multiple databases in your zephyr actions. to use multiple databases just create some instance of abstractdbinfo class. then you just need to pass each instant of abstractdbinfo to DAO for succeessive multiple db operation. if you use different providers, then you can use multiple instance of abstract dbinfo as described above. but if you are using same provider, unfortunately you will get multiple database support only if your database provider is mysql. right now we are working for multiple database support in SQLite and postgresql. hopefully you will get this support in next release of zephyr. <<-example for different providers->>we already said that we need to mutiple instance of dbinfo class which is actually developed by extending abstractdbinfo. in the following example, we will use two dbinfo class, one for mysql and another for sqlite. following is the dbinfo class for mysql database, placed inside "helper" folder inside our package.
//mysql_db.class.php
<?
class mysql_db extends abstractdbinfo
{
public function __construct()
{
$this->dbhost = "localhost";
$this->dbname = "mysql_db";
$this->dbuser = "root";
$this->dbpwd = "root";
$this->dbtype = "mysql";
$this->persist = 1;
}
}
?>
Now we will define another dbinfo class which we will use for SQLite database. we will place this class in "helper" folder inside our package. //sqlite_db.class.php
<?
class sqlite_db extends abstractdbinfo
{
public function __construct()
{
$pm = new packagemanager();
$package_path = $pm->get_package_path(); //physical path to this package
$this->dbhost = $package_path."/sqlitedb/";
$this->dbname = "test.sqlite";
$this->dbtype = "sqlite";
$this->persist = 1;
}
}
?>
well, lets use these two dbinfo class inside our action. all you have to do is to pass name of these two dbinfo class explicitely in two instance of DAO. lets see //multipledb_action
//multiple_db.class.php
<?
class sqlite_db extends abstractdbinfo
{
public function execute()
{
$dao_mysql = new DAO("","mysql_db");
$dao_sqlite = new DAO("","sqlite_db");
//or you can use your DB domain model while initialization
$domain1 = new domain1();
$domain2 = new domain2();
$dao_mysql = new DAO($domain1,"mysql_db");
$dao_sqlite = new DAO($domain2,"sqlite_db");
//$dao->execute("query for mysql db");
//$dao->execute("query for sqlite db");
}
}
?>
<<-example for single providers->>if your db provider is mysql, then you can manage multiple db from single provider (that is mysql). we are working to provide support for other db engine as well. |