'connections' => array(
//默認mysql配置,訪問test庫
'mysql' => array(
'driver' => 'mysql',
'host' => '192.168.16.70',
'port' => '3306',
'database' => 'test',
'username' => 'test',
'password' => '123456',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
//自定義mysql連接,訪問media庫
'media' => array(
'read' => array(
array('host' => '192.168.16.74','port' => 3306),
array('host' => '192.168.16.70','port' => 3306),
),
'write' => array(
'host' => '192.168.16.70', 'port'=> 3306
),
'driver' => 'mysql',
'database' => 'media',
'username' => 'test',
'password' => '123456',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
)
這樣使用,新建一模型User.php
class User extends Eloquent{
//不設置屬性,默認連接mysql配置
protected $connection = 'media';
}
