Connection to a Database in Codeigniter
filed in General on Jun.12, 2009
CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.
If you want to do things like want a framework with a small footprint, need exceptional performance, need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations, want a framework that requires nearly zero configuration, want a framework that does not require you to use the command line,want a framework that does not require you to adhere to restrictive coding rule then codeigniter is the right place for you.
In two ways we can connect to a database in codeigniter.
Auto connect: If you enable auto connect option the database class will be loaded with every page. To enable this go to application.config/autoload. in the library array add the word ‘database’.
Manually connect: We need to connect manually always. The above example can be used in class constructor to make the database available globally in that class.
Now we have to talk to CodeIgniter to connect the database. To do this go to config folder and click on database.php and change the database to the database name u created(i.e-user) and set your hostname, username, password, and dbdriver connection. After saving this CodeIgniter will automatically connect to the database. For easy and simple learning you can visit http://www.codesnipr.com/snippet/767/Codeigniter-Database-connection.
Leave a Reply