douqiang1910 2013-09-19 18:14
浏览 101
已采纳

laravel 4多个DB连接

Playing around with laravel 4 and was wondering if there is a way to run migrations on different connections, so if I have as default:

'sqlsrv' => array(
    'driver'   => 'sqlsrv',
    'host'     => '192.168.1.11\SQLEXPRESS',
    'database' => 'database1',
    'username' => 'sa',
    'password' => 'password',
    'prefix'   => '',
    ),

But I want a different migration to go here:

'sqlsrv2' => array(
    'driver'   => 'sqlsrv',
    'host'     => '192.168.1.11\SQLEXPRESS',
    'database' => 'database2',
    'username' => 'sa',
    'password' => 'password',
    'prefix'   => '',
    ),

I have no doubt there is a way to do it, but I'm not finding it in the docs. :)

  • 写回答

2条回答 默认 最新

  • dpwbc42604 2013-09-19 18:28
    关注

    From the docs at http://laravel.com/docs/schema#creating-and-dropping-tables

    To specify which connection the schema operation should take place on, use the Schema::connection method:

    Schema::connection('foo')->create('users', function($table)
    {
        $table->increments('id');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作