Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Database connectivity in ci
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
6. Automatically Connecting
• Models are PHP classes that are designed to
work with information in your database.
• The "auto connect" feature will load and
instantiate the database class with every page
load. To enable "auto connecting", add the
word database to the library array, as
indicated in the following file:
• application/config/autoload.php
7. Continue..
These are the things you can load automatically:
• 1. Packages
• 2. Libraries
• 3. Helper files
• 4. Custom config files
• 5. Language files
• 6. Models
8. Manually Connecting
• If only some of your pages require database
connectivity you can manually connect to your
database by adding this line of code in any
function where it is needed, or in your class
constructor to make the database available
globally in that class.
• $this->load->database();
• When a model is loaded it does not connect
automatically to your database.
• $this->load->model('Model_name', ' ', TRUE);
9. Database Configuration
• CodeIgniter has a config file that lets you store
your database connection values (username,
password, database name, etc.).
• The config file is located
at application/config/database.php. You can
also set database connection values for
specific environments by
placing database.php it the respective
environment config folder.
10.
11. Reconnecting / Keeping the
Connection Alive
• If the database server's idle timeout is
exceeded while you're doing some heavy PHP
lifting (processing an image, for instance), you
should consider pinging the server by using
the reconnect() method before sending
further queries, which can gracefully keep the
connection alive or re-establish it.
• $this->db->reconnect();
12. Manually closing the Connection
• While CodeIgniter intelligently takes care of
closing your database connections, you can
explicitly close the connection.
• $this->db->close();
13. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
www.baabtra.com | www.massbaab.com |www.baabte.com
14. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Notas do Editor
You can tell the model loading function to auto-connect by passing TRUE (boolean) via the third parameter, and connectivity settings, as defined in your database config file will be used:S