post by gangio75 on Sep 29, 2022

Hi all,
in the past version of Codeigniter + GroceryCrud switching database was a simply as this:
$this->db = $this->load->database(‘new_db’, true);

Now
$crud = new GroceryCrud();
$this->db = db_connect(‘new_db’);
seems not working: the accessed db remains the default one.

Any clues?

1 month later

post by resteve on Nov 3, 2022

12 days later

post by gangio75 on Nov 16, 2022

Unfortunately, no.
There is a function in grocery enterprise ( setDatabaseSchema ) but it says only for PostgresSQL.

post by resteve on Nov 16, 2022

9 days later

post by gangio75 on Nov 25, 2022

Sorry but I could’nt reproduce…
What does the function datos_user() do?

And in which part of it you actually connect to db?

post by gangio75 on Nov 25, 2022

I found a simple solution although, as is often the case with the new version of grocerycrud, it is not documented and you need to reverse engineer the sources.

Just define a new custom model, which is actually the default one.
But in this case, you can pass the correct DB connection to the constructor:
$crud->setModel(new \App\Models\GroceryCrudModel(db_connect(‘db_to_connect’)));

1 / 6
Sep 2022