• <bdo id='4KSkk'></bdo><ul id='4KSkk'></ul>

    <small id='4KSkk'></small><noframes id='4KSkk'>

      <tfoot id='4KSkk'></tfoot>
      <i id='4KSkk'><tr id='4KSkk'><dt id='4KSkk'><q id='4KSkk'><span id='4KSkk'><b id='4KSkk'><form id='4KSkk'><ins id='4KSkk'></ins><ul id='4KSkk'></ul><sub id='4KSkk'></sub></form><legend id='4KSkk'></legend><bdo id='4KSkk'><pre id='4KSkk'><center id='4KSkk'></center></pre></bdo></b><th id='4KSkk'></th></span></q></dt></tr></i><div id='4KSkk'><tfoot id='4KSkk'></tfoot><dl id='4KSkk'><fieldset id='4KSkk'></fieldset></dl></div>

      <legend id='4KSkk'><style id='4KSkk'><dir id='4KSkk'><q id='4KSkk'></q></dir></style></legend>

        在 laravel 模型中更改数据库连接

        时间:2023-10-31

        <tfoot id='UhXat'></tfoot>

            <i id='UhXat'><tr id='UhXat'><dt id='UhXat'><q id='UhXat'><span id='UhXat'><b id='UhXat'><form id='UhXat'><ins id='UhXat'></ins><ul id='UhXat'></ul><sub id='UhXat'></sub></form><legend id='UhXat'></legend><bdo id='UhXat'><pre id='UhXat'><center id='UhXat'></center></pre></bdo></b><th id='UhXat'></th></span></q></dt></tr></i><div id='UhXat'><tfoot id='UhXat'></tfoot><dl id='UhXat'><fieldset id='UhXat'></fieldset></dl></div>
            1. <small id='UhXat'></small><noframes id='UhXat'>

                <tbody id='UhXat'></tbody>
              <legend id='UhXat'><style id='UhXat'><dir id='UhXat'><q id='UhXat'></q></dir></style></legend>
                <bdo id='UhXat'></bdo><ul id='UhXat'></ul>

                • 本文介绍了在 laravel 模型中更改数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我使用 Laravel 4.2,我想要在我的一个模型中使用 external 数据库,这是我的模型代码:

                  So i work with Laravel 4.2, what i want is in one of my models use an external database, this is my model code :

                  <?php
                  class McibModel extends Eloquent {
                      /**
                        * The database table used by the model.
                        *
                        * @var string
                        */
                      //here i should call the external database table
                      protected $table = 'agencies';
                  }
                  

                  所以,如果有人有任何想法,我将非常感激.

                  So please if someone has any idea i will be very appreciative.

                  推荐答案

                  不同的模型可以有不同的数据库连接.所以您的模型使用正常的默认连接 - 但您的McibModel"模型可以使用另一个连接:

                  Different models can have different database connections. So your models use the normal default connection - but your 'McibModel' model can use another connection:

                  class McibModel extends Model {
                  
                      protected $connection= 'second_db_connection';
                  
                      protected $table = 'agencies';
                  
                  }
                  

                  然后在您的数据库连接文件中 - 您将拥有如下内容:

                  Then in your DB connection file - you would have something like this:

                  return array(
                      'connections' => array(
                          'mysql' => array(
                              'driver'    => 'mysql',
                              'host'      => 'localhost',
                              'database'  => 'database1',
                              'username'  => 'user1',
                              'password'  => 'pass1'
                              'charset'   => 'utf8',
                              'collation' => 'utf8_unicode_ci',
                              'prefix'    => '',
                          ),
                  
                          'second_db_connection' => array(
                              'driver'    => 'mysql',
                              'host'      => 'localhost',
                              'database'  => 'database2',
                              'username'  => 'user2',
                              'password'  => 'pass2'
                              'charset'   => 'utf8',
                              'collation' => 'utf8_unicode_ci',
                              'prefix'    => '',
                          ),
                      ),
                  

                  这篇关于在 laravel 模型中更改数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel Auth:attempt() 不会持久登录 下一篇:如何在 Laravel 中使用 SQL Server 连接?

                  相关文章

                    <tfoot id='JSLj3'></tfoot>
                    <i id='JSLj3'><tr id='JSLj3'><dt id='JSLj3'><q id='JSLj3'><span id='JSLj3'><b id='JSLj3'><form id='JSLj3'><ins id='JSLj3'></ins><ul id='JSLj3'></ul><sub id='JSLj3'></sub></form><legend id='JSLj3'></legend><bdo id='JSLj3'><pre id='JSLj3'><center id='JSLj3'></center></pre></bdo></b><th id='JSLj3'></th></span></q></dt></tr></i><div id='JSLj3'><tfoot id='JSLj3'></tfoot><dl id='JSLj3'><fieldset id='JSLj3'></fieldset></dl></div>

                    <small id='JSLj3'></small><noframes id='JSLj3'>

                        <bdo id='JSLj3'></bdo><ul id='JSLj3'></ul>
                    1. <legend id='JSLj3'><style id='JSLj3'><dir id='JSLj3'><q id='JSLj3'></q></dir></style></legend>