How To Connect Database In CodeIgniter With Example

5
218
ci connection

First, you need to make sure that you have the correct configuration settings for your database. You can find these settings in the application/config/database.php file. In this file, you will need to specify your hostname, username, password, and database name. Once you have entered these settings, you will then be able to connect to your database.

For example:

$db[‘default’] = array(
‘dsn’ => ”,
‘hostname’ => ‘localhost’,
‘username’ => ‘root’,
‘password’ => ”,
‘database’ => ‘test_db’
);

Next, you will need to load the database driver. You can do this by adding the following line of code to your application/config/autoload.php file:

$autoload[‘libraries’] = array(‘database’);

Once the database driver has been loaded, you will then be able to use CodeIgniter’s Database class methods to interact with your database. For example, if you wanted to run a query on your database, you could use the following code:

$query = $this->db->query(“YOUR QUERY HERE”);

If you want to learn more about working with databases in CodeIgniter, we recommend reading through the official documentation: https://www.codeigniter.com/user_guide/database

5 COMMENTS

  1. Wow, superb blog layout! How lengthy have you ever been running a
    blog for? you made running a blog look easy.
    The whole glance of your web site is wonderful, let alone the content!

    You can see similar here e-commerce

LEAVE A REPLY

Please enter your comment!
Please enter your name here