Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
I can not change DB connection from one to the other inside module
soseki
March 2019
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){
\Log::error($e->getMessage());
}
}
return $this->response(array('data'=>array()));
}
Also, I set
$_connection = 'test2' in
Model_Test
and call something like this.
$query = 'select * from tests';
\DB::query($query,\DB::SELECT)->execute('test2');
But, it dose not connect to test2.
Do you know what is wrong with this?
Best regards
Harro
March 2019
Accepted Answer
I can't reproduce that.
See
https://bin.fuelphp.com/snippet/view/O5
for my test code and result.
soseki
March 2019
The reason why I could not connect to test2 database is that the parameter was wrong like following.
・Wrong parameter
\DB::list_columns($table_no,'test2');
・Correct parameter
\DB::list_columns($table_no,null,'test2');
soseki
March 2019
Thank you very much for your help
:)
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,086
General
↳ General
3,362
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
March 2019
soseki
March 2019