CodeIgniter Forums
how to access database created with dbforge - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to access database created with dbforge (/showthread.php?tid=73420)



how to access database created with dbforge - majortom84 - 04-22-2019

Hello!

I'm kinda new with dbforge. I have some questions.

1. If a database is created using dbforge, can you use query builder for the dynamic database(insert, update, delete)?  

2. If you can't use query builder on the dbforge created database, do you just have to build queries with "$this->db->query("YOUR QUERY")"?

3. How do you "select" the dbforge created database to preform queries on? ("$this->db->query('use db2');" so, this is the 'use' statement and it works the same as in SQL syntax?)

Thank you!


RE: how to access database created with dbforge - dave friend - 04-22-2019

(04-22-2019, 10:23 AM)majortom84 Wrote: 1. If a database is created using dbforge, can you use query builder for the dynamic database(insert, update, delete)?  

In a word, yes.

(04-22-2019, 10:23 AM)majortom84 Wrote: 3. How do you "select" the dbforge created database to preform queries on? ("$this->db->query('use db2');" so, this is the 'use' statement and it works the same as in SQL syntax?)

Consult the documentation on Database Configuration. Down that page a way it describes how you can store multiple sets of connection values. If your dbforge database connection is stored like this

PHP Code:
$db['forged'] = array( 
 
       dsn'   => '',
        '
hostname' => 'localhost',
        etc...
); 

That database could be loaded like this.

PHP Code:
$this->load->database('forged'); 

After which you simply use

PHP Code:
$this->db->query_builder_methods_here(); 

The Connecting to Your Database documentation is helpful too.