Speed up development with full-stack environments for every branch.Learn More
How to use MySQL in CodeIgniter
This code example shows how to connect to a mySQL database and use Models to setup basic functions to create tables, add records and get the row count. Changes were made with the following:
controller.php - the Controller file used to connect to the database, load the Model, and use the Model to execute database operations. It's located under /applications/controllers.
simple_model.php - the Model file that contains functions that perform queries on the database to retrieve data and make changes. It's located under /application/models.
database.php - a config file that contains information necessary to connect to the database, such as the host, username, password, and port. The values specified in this file are specific to Runnable, and should be changed when running this code on another server. It's located under /application/config.
routes.php - a config file used to specify which Controller to use when the user navigates to a specific route. The change was made to use "controller.php". It's located under /application/config.