Codeigniter Interview Questions

Ques: How will you connect multiple databases in Codeigniter ?

Ans. In Application/Config/database.php –

Copy default database connection array and paste it and change database connection details and change the $db[‘default’] to $db[‘new_db’] in pasted array.

In model – 

public function __construct(){

parent::__construct();

$this->cipaypal_db = $this->load->database(‘new_db’,TRUE); 

/* $this->cipaypal_db = Variable Name and in $this->load->database(name) = should be same as $db[name] in database.php file */

}

Ques: What are logs in codeigniter ? What is the meaning of log status(0,1,2,3,4) ?

Ans. Logs are used for error handling. You can write your own message in it.

0 = Disables logging, Error logging TURNED OFF

1 = Error Messages (including PHP errors)

2 = Debug Messages

3 = Informational Messages

4 = All Messages

Ques: What are hooks ? Name all hooks.

Ans. Hooks are used to override the default functionality of codeigniter.

To enable hooks – 

$config[‘enable_hooks’] = TRUE;  /Application/config.php

There are 7 types of hooks available in codeigniter –

1.) pre_system

2.) pre_controller

3.) post_controller_constructor

4.) post_controller

5.) display_override

6.) cache_override

7.) post_system

Ques: Which protocol is used in Routing ?

Ans: Transmission Control Protocol (TCP).

Ques: How will you make database connection in routes in Codeigniter ? How will you define routing based on database value ?

Ans: require_once( BASEPATH .’database/DB.php’ );   //Include file

$db =& DB(); //Create instance of database

$query = $db->get( ‘table’ ); //Table for routing base on which routing will be done. 

$result = $query->result();

Ques: What are in inhibitors ?

Ans: It is a class that handles the error. It uses PHP native error handling functions like set_error_handler, get_exception_handler, register_shutdown_function to handle errors.

Ques: Where routing is defined in Codeigniter ?

Ans: In application/configuration/routes.php

One thought on “Codeigniter Interview Questions”

Leave a Reply

Your email address will not be published. Required fields are marked *