<tfoot id='BwEHl'></tfoot>

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

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

        Laravel 4 - 连接到其他数据库

        Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)

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

              <tbody id='Cu30A'></tbody>

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

          1. <tfoot id='Cu30A'></tfoot>

              • <legend id='Cu30A'><style id='Cu30A'><dir id='Cu30A'><q id='Cu30A'></q></dir></style></legend>
                  <bdo id='Cu30A'></bdo><ul id='Cu30A'></ul>

                  本文介绍了Laravel 4 - 连接到其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有时想连接到另一个数据库.

                  I want to connect to another database sometimes.

                  我用数据库连接数据创建了一个config.php.

                  I created a config.php with the database connection data.

                  但是我怎样才能告诉 laravel 使用 config/database.php 连接到这个数据库呢?

                  But how can i tell laravel to connect to this database insted of using the config/database.php?

                  例如在使用 Schema 类时.

                  因为似乎没有人明白我想要什么.

                  Since no one seems to understand what i want.

                  我不想使用 config/database.php,我想在不同的位置使用不同的配置文件.

                  推荐答案

                  听起来你想通了.无论如何,如果其他人进来,或者如果有什么对你有用的东西,这就是我将如何完成它.

                  It sounds like you figured this out. Here's how I'd accomplish it anyway for other people coming in, or in case something useful is here for you.

                  首先,在app/config/database.php中添加第二个连接.注意:该文件路径可能会根据您的环境而变化.

                  First, Add a second connection in app/config/database.php. Note: That file path may change depending on your environment.

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

                  第二,在您的代码中,您可以使用(如前所述)您想要的第二个连接:

                  Second, in your code, you can use (as mentioned) the 2nd connection where you would like:

                  Schema::connection('mysql2')->create('users', function($table) {})

                  关于此的更多文档 - 请参阅 访问连接.

                  There's more documentation on this - see Accessing Connections.

                  雄辩的 ORM您可以在 eloquent 类中定义连接"的变量来设置使用哪个连接.基本用法部分对此进行了说明.

                  Eloquent ORM You can define the variable for "connection" in an eloquent class to set which connection is used. That's noted in the Basic Usage section.

                  在 这里查看该变量Github 以及您可以设置动态设置连接的方法 这里.

                  See that variable on here on Github and the method which you can set to set the connection dynamically here.

                  编辑OP 已经明确表示他们不希望使用 config/database.php 文件进行配置.

                  Edit The OP has made it clear that they do not wish to use the config/database.php file for config.

                  但是,如果没有进一步解释,我无法发表评论.我很乐意提供帮助 - 知道为什么不能/不应该使用 config/database.php 文件听起来很有用,因为这可以帮助我们确定问题并创建一个有用的解决方案.

                  However without explaining further, I can't comment. I'm happy to help - sounds like it would be useful to know why the config/database.php file can't/shouldn't be used, as this can help us ascertain the problem and create a useful solution.

                  这篇关于Laravel 4 - 连接到其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  • <small id='4G9vK'></small><noframes id='4G9vK'>

                        <tfoot id='4G9vK'></tfoot>
                      1. <legend id='4G9vK'><style id='4G9vK'><dir id='4G9vK'><q id='4G9vK'></q></dir></style></legend>

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

                          • <bdo id='4G9vK'></bdo><ul id='4G9vK'></ul>
                              <tbody id='4G9vK'></tbody>