Welcome Guest, Not a member yet? Register   Sign In
Database Connection (Confused by the bible)


I want to connect to MySQL database, but reading the bible has some what confused me!

I've put my username and password in config/database.php it then tells me in the bible

user_guide\database\connecting.html to Autoconnect to add database to config/autoload.php

$autoload['libraries'] = array('database');

and do I need to add the following to config/config.php


Is this the correct way to make sure it's alive no matter what model I create? or do I still have to add some more code within each model to make sure it's connecting? if not what exactly do I have to?

Also so's not to clogg up this forum with random posts, I want to create a simple navigation pulled from a Database table, whats the best approch for this?

Thanks in advance


Per the user guide, in application/config/database.php enter your database information:

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "database_name";
$db['default']['dbdriver'] = "mysql";

I typically manually connect and use for the pages that need a database connection:


I would try this and make sure you can connect manually before trying to autoload.

To Autoload, look in the application/config/autoload.php file and just add the word 'database' to the library array that is listed in the file. That's it.

Someone else will have to answer your question about the navigation menu, but frankly you should work through some simpler examples first to get your head around this framework.


Thanks Terry

So Basically I only need to amend the database.php and add
to the models that require the connection.

I take it autoload.php is if the full application requires a constant Database connection? or is that for something completely different?



You got it. And per the user guide, you can load your database from either the model or controller.


Theme © iAndrew 2016 - Forum software by © MyBB