- 我们可能会有多个数据库 (config/database.php)
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'superadmin',
'username' => 'root',
'password' => 'knwall',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'mysql2' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'framework',
'username' => 'root',
'password' => 'knwall',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
- 我们可以使用 Model 的
$connection
属性来指定当前模型使用指定的连接:
class Organization extends Eloquent{
// 不指定则使用默认的 "mysql
}
class FrameworkOrganization extends Eloquent{
protected $connection = 'mysql2'; /// Other connection
}
from : http://laravel.so/tricks/272ad5204a13b7e3c4b6c230874fb936
沒有留言:
張貼留言