我想在我的Laravel应用程序中使用MySQL和MongoDB。在这里,我想插入两个数据库(MySQL和MongoDB)并从MongoDB中选择。
答案 0 :(得分:-1)
连接定义:
应用程序/配置/ database.php中
return array(
'default' => 'mysql',
'connections' => array(
# Primary/Default database connection
'mysql' => array(
'driver' => 'mysql',
'host' => 'host1',
'database' => 'database1',
'username' => 'user1',
'password' => 'pass1'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
# Secondary database connection
'mysql2' => array(
'driver' => 'mysql',
'host' => 'host2',
'database' => 'database2',
'username' => 'user2',
'password' => 'pass2'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
转到架构构建器时:
Schema::connction('mysql2')->create('table', function($table)){
$table->increments('id')
});
查询
$users = DB::connection('mysql2')->select(...);
锋
类SomeModel扩展了Eloquent {
protected $connection = 'mysql2';
}