Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I can not change DB connection from one to the other inside module
  • Hello there,

    I have following config inside my module in config/development/db.php.

    return array(
      'default' => array(
        'connection'  => array(      
    'dsn'        => 'mysql:host=localhost;dbname=test',
          'username'   => 'root',
          'password'   => 'root',
      'test2' => array( 
    'type'        => 'pdo',
        'connection'  => array(
          'dsn'        => 'mysql:host=localhost;dbname=test2',
          'username'   => 'root',
          'password'   => 'root',

    Then, I try to connect those database inside my rest API.

      public function post_index()
        if(\Auth::check()) // It should connect to default
          try      {
            return $this->response(Model_Test::getData()); // It should connect test2
          }catch(\Exception $e){
        return $this->response(array('data'=>array()));

    Also, I set $_connection = 'test2' in Model_Test and call something like this.

    $query = 'select * from tests';

    But, it dose not connect to test2.

    Do you know what is wrong with this?

    Best regards
  • HarroHarro
    Accepted Answer
    I can't reproduce that.

    See for my test code and result.
  • The reason why I could not connect to test2 database is that  the parameter was wrong like following.

    ・Wrong parameter

    ・Correct parameter

  • Thank you very much for your help :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion