laravel 5 多数据库配置和 怎么操作多数据库
我找了下网上的 关于《 Multiple DB Connections in Laravel 》
Eloquent
You can also define which connection to use in your Eloquent models as well!
One way is to set the $connection variable in your model:
<?php
class SomeModel extends Eloquent {
protected $connection = 'mysql2';
}
You can also define the connection at runtime via the setConnection method.
<?php
class SomeController extends BaseController {
public function someMethod()
{
$someModel = new SomeModel;
$someModel->setConnection('mysql2');
$something = $someModel->find(1);
return $something;
}
}
可是我打印了 发现database还是mysql1 有知道怎么做的能给我列子吗
Eloquent
You can also define which connection to use in your Eloquent models as well!
One way is to set the $connection variable in your model:
<?php
class SomeModel extends Eloquent {
protected $connection = 'mysql2';
}
You can also define the connection at runtime via the setConnection method.
<?php
class SomeController extends BaseController {
public function someMethod()
{
$someModel = new SomeModel;
$someModel->setConnection('mysql2');
$something = $someModel->find(1);
return $something;
}
}
可是我打印了 发现database还是mysql1 有知道怎么做的能给我列子吗
3 个回复
赵狗胜 - 谢谢帮助过我的人!
赞同来自:
这个mmm,就是另一个数据库的链接了。
$someModel->setConnection('mmm');
赵狗胜 - 谢谢帮助过我的人!
赞同来自:
游戏
赞同来自: