Practice these MCQs to strengthen your PHP and CodeIgniter knowledge and prepare confidently for job interviews or certification exams.
Whether you’re aiming to become a backend specialist, a full-stack developer, or simply sharpen your skills in MVC architecture, REST APIs, database integration, and server-side scripting — you’re in the right place.
50+ PHP CodeIgniter MCQs covering everything from core PHP syntax, routing, controllers, models, views, helpers, sessions, validation, and security — complete with answers to help you test and solidify your understanding, no guesswork involved.
✅ Section 1: Core PHP Basics – 10 MCQs
- What is the correct way to start a PHP block?
A. <?php ?>
B. <php> </php>
C. <? ?>
D. <!php> </!php>
✅ Answer: A - Which of the following is used to declare a variable in PHP?
A. $var = 10;
B. int var = 10;
C. declare var = 10;
D. var := 10;
✅ Answer: A - What is the output of echo 5 + ‘5 days’; in PHP?
A. 55
B. 10
C. Error
D. 5 days
✅ Answer: B - Which function is used to include one PHP file into another?
A. insert()
B. require()
C. echo()
D. printf()
✅ Answer: B - Which of these is NOT a PHP superglobal?
A. $_POST
B. $_DATA
C. $_GET
D. $_SESSION
✅ Answer: B - What does the isset() function check?
A. If variable is empty
B. If variable exists and is not NULL
C. If variable is boolean
D. If variable is numeric
✅ Answer: B - How are arrays defined in PHP?
A. arr = [1, 2, 3];
B. $arr = array(1, 2, 3);
C. int[] arr = {1, 2, 3};
D. $arr = new array[1,2,3];
✅ Answer: B - What is the default method for HTML forms?
A. GET
B. POST
C. PUT
D. DELETE
✅ Answer: A - Which operator is used for string concatenation in PHP?
A. +
B. .
C. &
D. ::
✅ Answer: B - What does die() do in PHP?
A. Kills the browser
B. Deletes a variable
C. Terminates script execution
D. Loops forever
✅ Answer: C
Master PHP with CodeIgniter – Build Dynamic Web Apps in Gurgaon
✅ Section 2: CodeIgniter Fundamentals – 10 MCQs
- CodeIgniter is based on which design pattern?
A. Singleton
B. Factory
C. MVC
D. Proxy
✅ Answer: C - Which folder contains user-defined controllers in CodeIgniter?
A. system/controllers/
B. application/controllers/
C. core/controllers/
D. assets/controllers/
✅ Answer: B - What is the default controller in CodeIgniter 3?
A. index.php
B. main.php
C. Welcome.php
D. home.php
✅ Answer: C - How do you load a model in CodeIgniter?
A. $this->model(‘modelname’);
B. $this->load->model(‘modelname’);
C. include ‘modelname.php’;
D. $model = new Model();
✅ Answer: B - What is the purpose of a model in MVC?
A. Handle database operations
B. Manage routing
C. Generate HTML
D. Process CSS
✅ Answer: A - Where are view files stored in CodeIgniter?
A. application/html/
B. application/templates/
C. application/views/
D. system/views/
✅ Answer: C - How do you pass data to a view in CodeIgniter?
$this->load->view(‘example’, $data);
A. True
B. False
✅ Answer: A
- Which helper helps with form creation?
A. form_helper
B. html_helper
C. url_helper
D. input_helper
✅ Answer: A - What does $this->input->post(’email’) do?
A. Loads email library
B. Fetches POST data from form
C. Sends email
D. Sets a session variable
✅ Answer: B - How do you load a helper in CodeIgniter?
A. helper(‘url’);
B. load_helper(‘url’);
C. $this->helper(‘url’);
D. $this->load->helper(‘url’);
✅ Answer: D‘
✅ Section 3: Routing & URL Handling – 10 MCQs
- Which file defines URL routes in CodeIgniter?
A. routes.php
B. config.php
C. web.php
D. index.php
✅ Answer: A - Which function redirects to another controller method?
A. redirect()
B. send()
C. goto()
D. call()
✅ Answer: A - What is URI segment in CodeIgniter?
A. Path in HTML
B. Part of URL after base URL
C. Session name
D. Cookie identifier
✅ Answer: B - Which CodeIgniter function retrieves URL segment?
A. get_uri()
B. $this->uri->segment()
C. uri_part()
D. url()->segment()
✅ Answer: B - Which config item changes the base URL?
A. routes.php
B. index.php
C. config.php
D. constants.php
✅ Answer: C - How to enable pretty URLs in CI (remove index.php)?
A. Configure .htaccess
B. Rename router
C. Use query strings
D. Edit views
✅ Answer: A - Which function sets a custom route?
$route[‘products’] = ‘productController/index’;
A. True
B. False
✅ Answer: A
From Beginner to Backend Pro – CodeIgniter Training in Gurgaon
- What does $config[‘base_url’] define?
A. Default route
B. Base system path
C. Application root URL
D. Admin panel URL
✅ Answer: C - Which method loads a library in CodeIgniter?
A. library_load(’email’);
B. $this->load->library(’email’);
C. use email;
D. import email;
✅ Answer: B - How to call controller method from browser URL?
A. /controller-method
B. /index.php/controller/method
C. /site.controller.method
D. /call/controller.method
✅ Answer: B
✅ Section 4: Database Integration – 10 MCQs
- Which function executes a SQL query in CodeIgniter?
A. $this->query();
B. $this->db->query();
C. runQuery();
D. $this->execute();
✅ Answer: B - How do you enable the database in CodeIgniter?
A. Create db.php
B. Load DB library manually
C. Edit application/config/database.php
D. Create .sql file
✅ Answer: C - What function returns query result as array of objects?
A. result()
B. fetch_all()
C. object()
D. query_result()
✅ Answer: A - Which method inserts a record into the database?
A. $this->db->add()
B. $this->db->insert()
C. $this->db->create()
D. $this->insert_row()
✅ Answer: B - How do you get the last inserted ID?
A. $this->db->last_insert_id()
B. $this->db->last_id()
C. $this->db->insert_id()
D. $this->insert->id()
✅ Answer: C - Which method fetches a single row from result?
A. row()
B. one()
C. fetch()
D. first()
✅ Answer: A - How do you write a where condition in CI?
$this->db->where(‘id’, 1);
A. True
B. False
✅ Answer: A
- Which method updates records?
A. $this->db->edit()
B. $this->db->update()
C. $this->db->change()
D. $this->db->save()
✅ Answer: B - What returns the total number of affected rows?
A. $this->db->rows()
B. $this->db->affected_rows()
C. get_row_count()
D. $this->affected()
✅ Answer: B - Which CodeIgniter file defines DB connection credentials?
A. config.php
B. autoload.php
C. database.php
D. routes.php
✅ Answer: C
Learn PHP CodeIgniter in Gurgaon – Code Faster, Smarter, Better
✅ Section 5: Sessions, Validation & Security – 10 MCQs
- Which function sets session data in CI?
A. set_session()
B. $this->session->set_userdata()
C. $this->set->session()
D. session()->set()
✅ Answer: B - How to retrieve session value named user_id?
A. $this->session->user_id;
B. $this->session->get(‘user_id’);
C. $this->session->userdata(‘user_id’);
D. $_SESSION[‘user_id’];
✅ Answer: C - Which library is used for form validation?
A. form_lib
B. validate
C. form_validation
D. validator
✅ Answer: C - What does xss_clean() do?
A. Sanitizes HTML
B. Prevents Cross-Site Scripting
C. Checks sessions
D. Encrypts URLs
✅ Answer: B - Which helper helps in URL creation and manipulation?
A. path_helper
B. html_helper
C. url_helper
D. uri_helper
✅ Answer: C - Which library encrypts session data?
A. crypto_lib
B. encrypt
C. encryption
D. secure_data
✅ Answer: C - What function validates an email field in form validation?
A. email_valid
B. valid_email
C. check_email
D. is_email
✅ Answer: B - Which file sets autoloaded libraries and helpers?
A. database.php
B. routes.php
C. autoload.php
D. config.php
✅ Answer: C - What is CSRF in CodeIgniter?
A. Cookie Security Rule Filter
B. Cross-Site Request Forgery protection
C. Client-Side Render Form
D. Cross Server Routing Filter
✅ Answer: B - How do you enable CSRF protection in CodeIgniter?
A. .htaccess
B. Modify autoload.php
C. $config[‘csrf_protection’] = TRUE; in config.php
D. $this->enable_csrf();
✅ Answer: C
Mastering these PHP CodeIgniter MCQs is a valuable step toward building a strong foundation in backend development, MVC architecture, RESTful APIs, and dynamic server-side scripting.
If you’re ready to elevate your career with hands-on projects and expert-led instruction, join our PHP CodeIgniter course in Gurgaon at Gyansetu and become industry-ready for high-demand backend and full-stack development roles.