About this Question Bank
This panel collects every question from the course in one place: 615 questions with answers and the answer key for 205 MCQs from 41 chapters and the project, plus 20 PHP & MySQLi interview questions. Use it for revision, then take the mock papers.
PHP & MySQLi Interview Questions and Answers
Ch-1 : AMP Basics : AMP Basics – Apache, MySQL and PHP
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | The term "open source" was coined in: | C. 1998 |
| 2 | In the AMP restaurant analogy, PHP plays the role of the: | B. Waiter |
| 3 | Which component of the AMP stack is the web server? | C. Apache |
| 4 | PHP: Hypertext Preprocessor is an example of a: | A. Recursive acronym |
| 5 | Which database server does current XAMPP actually ship under the "MySQL" label? | D. MariaDB |
Ch-2 : XAMPP : XAMPP – Installation, Configuration and Use
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | In XAMPP, the "M" now stands for: | B. MariaDB |
| 2 | The default web root folder of XAMPP on Windows is: | C. C:\xampp\htdocs |
| 3 | The default port of MySQL/MariaDB in XAMPP is: | D. 3306 |
| 4 | Which file must be edited to change the PHP upload limit? | C. php.ini |
| 5 | Which Control Panel button shows which program is using a port? | A. Netstat |
Ch-3 : Introduction & Syntax : PHP – Hypertext Preprocessor: Introduction and Syntax
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | PHP code is executed: | B. On the web server |
| 2 | Which tag correctly starts a portable PHP block? | A. <?php |
| 3 | Which statement about print is TRUE? | B. It always returns 1 |
| 4 | Which of these is case-sensitive in PHP? | C. Variable names |
| 5 | Which symbol does NOT start a comment in PHP? | D. <!-- |
Ch-4 : Constants, Variables & Data Types : Constants, Variables and Data Types
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which is a valid variable name? | C. $_first_name |
| 2 | A constant created with define() is used: | B. Without a $ prefix |
| 3 | What does "10" + 5 evaluate to? | B. 15 |
| 4 | A variable that keeps its value between function calls is declared with: | B. static |
| 5 | In which PHP version was register_globals removed? | C. 5.4 |
Ch-5 : Operators : Operators and Expressions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | What is the value of 2 + 3 * 3? | B. 11 |
| 2 | 5 === "5" evaluates to: | B. false |
| 3 | If $v = 5, what does echo $v++; print? | B. 5 |
| 4 | Which operator appends a string to a variable? | C. .= |
| 5 | $name = $_GET['name'] ?? 'Guest'; uses the: | B. Null coalescing operator |
Ch-6 : Conditional Statements : Conditional Statements
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which statement selects one of many blocks by comparing one value with several labels? | B. switch |
| 2 | What happens if break is omitted at the end of a case? | C. Execution falls through to the next case |
| 3 | Which keyword introduces an extra condition after if? | B. elseif |
| 4 | The PHP 8 match expression compares values using: | B. === |
| 5 | Which closes an if block written in alternative syntax? | C. endif; |
Ch-7 : Loops : Looping Statements
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which loop always executes its body at least once? | C. do…while |
| 2 | Which loop is designed to iterate over arrays? | B. foreach |
| 3 | What does continue do? | B. Skips to the next iteration |
| 4 | How many times does for ($i = 0; $i < 5; $i++) execute its body? | B. 5 |
| 5 | In for (init; condition; increment), the init part runs: | C. Only once, before the loop starts |
Ch-8 : Strings : PHP and Strings
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | What does echo 'Hi\n$x'; print? | B. Hi\n$x |
| 2 | Which string syntax does NOT expand variables? | C. Nowdoc |
| 3 | A nowdoc identifier is written as: | C. <<<'EOT' |
| 4 | What is "\x41" in a double-quoted string? | B. A |
| 5 | Which function counts characters correctly in UTF-8 text? | C. mb_strlen() |
Ch-9 : Arrays : PHP and Arrays
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | What is the index of "BMW" in array("Saab", "Volvo", "BMW")? | B. 2 |
| 2 | $ages = ["Peter" => 32]; creates a(n): | B. Associative array |
| 3 | Which function converts array keys into variables? | C. extract() |
| 4 | Which function sorts by value and keeps the key–value association? | B. asort() |
| 5 | $families['Griffin'][2] accesses an element of a: | B. Multidimensional array |
Ch-10 : User-Defined Functions : User-Defined Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which keyword defines a function? | C. function |
| 2 | How do you pass a parameter by reference? | B. &$n |
| 3 | What does function greet($n, $g = "Hi") mean? | B. $g is optional with default "Hi" |
| 4 | Which PHP 8 feature allows format(1234.5, prefix: "Rs. ")? | B. Named arguments |
| 5 | Which is an arrow function? | B. fn($x) => $x * 2 |
Ch-11 : Form Handling : PHP Form Handling
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which array holds values sent by a form with method="post"? | B. $_POST |
| 2 | Which method displays form data in the browser's address bar? | C. GET |
| 3 | $_REQUEST contains the contents of: | B. $_GET, $_POST and $_COOKIE |
| 4 | Which function protects output against XSS? | B. htmlspecialchars() |
| 5 | To receive several checked checkboxes as an array, the field name should be: | B. hobby[] |
Ch-12 : Form Validation & RegEx : Form Validation and Regular Expressions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | The quantifier + means: | C. 1 or more |
| 2 | Which pattern matches exactly ten digits? | A. /^\d{10}$/ |
| 3 | What does preg_match() return when no match is found? | B. 0 |
| 4 | Which function should replace the removed /e modifier? | B. preg_replace_callback() |
| 5 | [^0-9] matches: | B. Any non-digit character |
Ch-13 : include / require : Server Side Includes – include and require
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | If the included file is missing, include produces a: | B. Warning |
| 2 | Which statement stops the script when the file cannot be loaded? | C. require |
| 3 | require_once prevents: | A. Loading a file more than once |
| 4 | Which is the best choice for a database connection file? | B. require_once |
| 5 | What does $c = require "config.php"; store in $c? | C. The value returned by config.php |
Ch-14 : File System : PHP and the File System
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which mode opens a file for writing and erases its existing content? | C. w |
| 2 | Which function reads a single line from a file? | B. fgets() |
| 3 | Which enctype is required for file uploads? | C. multipart/form-data |
| 4 | Which function permanently saves an uploaded file? | B. move_uploaded_file() |
| 5 | $_FILES["file"]["tmp_name"] contains: | B. The temporary path on the server |
Ch-15 : E-Mail : PHP and E-Mail
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which parameter of mail() is optional? | D. headers |
| 2 | Mail headers in a string are separated by: | B. \r\n |
| 3 | Which header is needed for HTML mail? | A. Content-type: text/html |
| 4 | E-mail header injection is prevented by: | B. Validating fields and rejecting newlines |
| 5 | In XAMPP, mailToDisk saves messages in: | B. C:\xampp\mailoutput |
Ch-16 : Namespaces : PHP Namespaces
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which keyword declares a namespace? | B. namespace |
| 2 | Which separator is used in namespace names? | C. \ |
| 3 | \strlen("x") inside a namespace calls: | B. The global strlen |
| 4 | Which statement imports a function from a namespace? | C. use function MyProject\connect; |
| 5 | What is __NAMESPACE__ in the global space? | C. An empty string |
Ch-17 : OOP – Classes & Objects : Object-Oriented PHP – Classes and Objects
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which keyword creates an object? | B. new |
| 2 | What is the name of the constructor method in PHP 8? | C. __construct() |
| 3 | A protected property can be accessed from: | C. The declaring class and its parent/child classes |
| 4 | Which replaces the removed __autoload() function? | A. spl_autoload_register() |
| 5 | Inside a static method you cannot use: | C. $this |
Ch-18 : OOP – Advanced : Object-Oriented PHP – Abstraction, Overloading, Iteration and Patterns
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | An abstract class: | B. Cannot be instantiated |
| 2 | A class can implement: | B. Many interfaces |
| 3 | Which magic method runs when a value is written to an inaccessible property? | B. __set() |
| 4 | Which interface needs only the getIterator() method? | C. IteratorAggregate |
| 5 | The Singleton pattern makes the constructor: | C. private |
Ch-19 : MVC : PHP and MVC (Model–View–Controller)
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | In MVC, the component that contains business logic and database access is the: | C. Model |
| 2 | Which component renders output for the user? | B. View |
| 3 | In the convention described, which file type should contain no SQL? | A. .phtml |
| 4 | A major benefit of MVC is: | B. Interchangeable components |
| 5 | MVC is considered an evolution of: | B. IPO (Input, Processing, Output) |
Ch-20 : Errors & Exceptions : Error and Exception Handling
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which function installs a user-defined error handler? | B. set_error_handler() |
| 2 | The default level of trigger_error() is: | C. E_USER_NOTICE |
| 3 | Which block always executes after try/catch? | B. finally |
| 4 | A custom exception class must: | B. Extend Exception |
| 5 | In PHP 8, both Exception and Error implement: | A. Throwable |
Ch-21 : Filters : PHP Filters
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | A validating filter returns what when the data is invalid? | B. false |
| 2 | Which constant reads a variable from the query string in filter_input()? | B. INPUT_GET |
| 3 | Range limits for FILTER_VALIDATE_INT are given in an array named: | C. "options" |
| 4 | Which filter calls a user-defined function? | A. FILTER_CALLBACK |
| 5 | Which filter is deprecated in PHP 8.1? | C. FILTER_SANITIZE_STRING |
Ch-22 : .htaccess Security : .htaccess Security
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which directive in httpd.conf must allow .htaccess files to be used? | B. AllowOverride |
| 2 | Which program creates Apache password files? | B. htpasswd |
| 3 | Require valid-user allows: | C. Any user listed in the AuthUserFile |
| 4 | Options -Indexes prevents: | B. Directory listings |
| 5 | Which module provides RewriteRule? | C. mod_rewrite |
Ch-23 : Apache & Array Functions : Apache and Array Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which function adds elements to the beginning of an array? | B. array_unshift() |
| 2 | array_diff([1,2,3], [2,3,4]) returns: | A. [1] |
| 3 | Which function keeps key/value pairs while sorting by value in descending order? | C. arsort() |
| 4 | Which function returns one column of a two-dimensional array? | A. array_column() |
| 5 | Which array function no longer exists in PHP 8? | B. each() |
Ch-24 : Date / Time Functions : Date, Time and Calendar Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which format character prints the full name of the day? | C. l |
| 2 | date("H") returns the hour in: | B. 24-hour format with leading zero |
| 3 | Which function validates a date? | B. checkdate() |
| 4 | The Unix Epoch is: | B. 1 January 1970 GMT |
| 5 | Which function is deprecated since PHP 8.1? | C. strftime() |
Ch-25 : Class, Directory & File Functions : Class/Object, Function Handling, Directory and File Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which function returns the name of an object's class? | A. get_class() |
| 2 | Which function was removed in PHP 8.0? | B. create_function() |
| 3 | Which function lists files matching *.txt? | B. glob() |
| 4 | rmdir() succeeds only if the directory is: | B. Empty |
| 5 | Which function parses a line of a CSV file into an array? | B. fgetcsv() |
Ch-26 : Error, HTTP, Mail & Math Functions : Error, HTTP, Mail and Mathematical Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which function rounds 4.1 up to 5? | C. ceil() |
| 2 | header("Location: home.php"); is used to: | B. Redirect the browser |
| 3 | Which error_log() message type appends to a file? | C. 3 |
| 4 | dechex(255) returns: | A. "ff" |
| 5 | For a secure OTP you should use: | C. random_int() |
Ch-27 : MySQL → MySQLi Functions : MySQL Functions and their MySQLi Equivalents
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | In which PHP version was the mysql extension removed? | C. 7.0 |
| 2 | The MySQLi procedural equivalent of mysql_query($sql) is: | B. mysqli_query($link, $sql) |
| 3 | $link->insert_id is the OOP equivalent of: | B. mysql_insert_id() |
| 4 | Which feature of MySQLi prevents SQL injection? | B. Prepared statements |
| 5 | Running mysql_connect() on PHP 8 gives: | B. Fatal error: Call to undefined function |
Ch-28 : Network, Buffer, Config & Session Functions : Network, Output Buffer, Configuration and Session Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | ip2long("192.168.1.10") returns: | B. An integer |
| 2 | Which function returns the buffer contents and deletes the buffer? | B. ob_get_clean() |
| 3 | Which function changes a php.ini setting for the current script only? | B. ini_set() |
| 4 | What does php_sapi_name() return under XAMPP's Apache? | B. apache2handler |
| 5 | Which session function was removed in PHP 5.4? | B. session_register() |
Ch-29 : String & Variable Functions : String, Variable and Miscellaneous Functions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which function splits a string into an array by a separator? | B. explode() |
| 2 | strcmp("apple", "apple") returns: | C. 0 |
| 3 | Which function should be used to store a password? | C. password_hash() |
| 4 | Which function was removed in PHP 7.0? | C. split() |
| 5 | empty("0") returns: | A. true |
Ch-30 : Cookies & Query Strings : State Management – Cookies and Query Strings
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | HTTP is a ______ protocol. | B. stateless |
| 2 | Which of these is a server-side state management option? | C. Session |
| 3 | How do you create a cookie that expires in one hour? | B. setcookie("c", "v", time() + 3600) |
| 4 | Most browsers limit a single cookie to about: | B. 4096 bytes |
| 5 | In page2.php?d1=23&d2=45, the value of d2 is read with: | C. $_GET['d2'] |
Ch-31 : Sessions : State Management – Sessions
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Where is session data stored? | B. On the server |
| 2 | The default name of the session cookie is: | B. PHPSESSID |
| 3 | Which superglobal stores session variables? | B. $_SESSION |
| 4 | Which function deletes all session data on the server? | C. session_destroy() |
| 5 | Which function was removed in PHP 5.4? | C. session_register() |
Ch-32 : MySQL Fundamentals : Database Support and MySQL Fundamentals
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which storage engine is the default in current MySQL/MariaDB and supports transactions? | C. InnoDB |
| 2 | Which data type stores exact monetary values? | B. DECIMAL |
| 3 | Which clause sorts the result of a SELECT? | B. ORDER BY |
| 4 | WHERE name LIKE 'A%' finds names that: | C. Start with A |
| 5 | Which statement removes a whole table? | B. DROP TABLE table |
Ch-33 : PHP/MySQL (classic API) : PHP and MySQL – The Classic mysql API
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which classic function is equivalent to the SQL command USE? | B. mysql_select_db() |
| 2 | Which loop is normally used to read all rows of a result set? | C. while ($row = …fetch_array($result)) |
| 3 | mysql_fetch_array() returns a row as: | C. An associative and numeric array |
| 4 | The default user name of MySQL/MariaDB in XAMPP is: | C. root |
| 5 | Classic mysql_* code on XAMPP 8 results in: | C. Fatal error: Call to undefined function |
Ch-34 : MySQLi – Procedural : PHP and MySQLi – Procedural Style
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | In the procedural style, the connection is passed to mysqli_query() as the: | B. First argument |
| 2 | Since PHP 8.1, a failed MySQLi query by default: | C. Throws mysqli_sql_exception |
| 3 | Which function returns all rows of a result at once? | B. mysqli_fetch_all() |
| 4 | Which function gives the number of rows changed by UPDATE? | B. mysqli_affected_rows() |
| 5 | Which fetch function lets you write $row->name? | C. mysqli_fetch_object() |
Ch-35 : MySQLi – Object Oriented : PHP and MySQLi – Object-Oriented Style
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which statement creates a MySQLi connection object? | B. new mysqli(...) |
| 2 | In OOP style, the number of rows in a SELECT result is: | B. $result->num_rows |
| 3 | $conn->insert_id returns: | B. The AUTO_INCREMENT id of the last INSERT |
| 4 | Which loop can iterate a mysqli_result directly? | B. foreach |
| 5 | MySQL error 1062 means: | C. Duplicate entry |
Ch-36 : Prepared Statements : MySQLi Prepared Statements, Transactions and Security
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Prepared statements protect against: | B. SQL injection |
| 2 | In bind_param("sid", $a, $b, $c), $b is bound as: | B. An integer |
| 3 | Which PHP 8.2 method prepares, binds and executes in one call? | B. $conn->execute_query() |
| 4 | Which method undoes all statements of the current transaction? | B. rollback() |
| 5 | Which function checks a password against a stored hash? | C. password_verify() |
Ch-37 : ODBC : Database Support using ODBC
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | ODBC stands for: | B. Open Database Connectivity |
| 2 | Which DSN type is visible to Apache running as a service? | C. System DSN |
| 3 | Which function moves to the next row of an ODBC result? | B. odbc_fetch_row() |
| 4 | odbc_result($rs, "CompanyName") returns: | B. The value of the CompanyName field of the current row |
| 5 | Which php.ini line enables ODBC? | A. extension=odbc |
Ch-38 : XML : XML with PHP
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | XML tags are: | B. Defined by the author |
| 2 | Which document is NOT well-formed? | B. <a><b>x</a></b> |
| 3 | Which PHP function loads an XML file into a SimpleXMLElement? | B. simplexml_load_file() |
| 4 | In SimpleXML, the attribute id of $book is read as: | B. $book['id'] |
| 5 | The DOM parser is a: | B. Tree-based parser |
Ch-39 : AJAX : PHP and AJAX
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | Which readyState value means the response is complete? | D. 4 |
| 2 | The third argument of xhr.open("GET", url, true) makes the request: | C. Asynchronous |
| 3 | Which property returns the server response as a string? | B. responseText |
| 4 | Which PHP function turns an array into JSON? | C. json_encode() |
| 5 | AJAX was originally made possible by an object first shipped in: | B. Internet Explorer 5 |
Ch-40 : CMS Concepts : Content Management System (CMS) – Concepts
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | The main reason users return to a web site is: | B. Regularly updated content |
| 2 | In a CMS, content should be: | B. Separate from the design |
| 3 | A newly submitted article in the project CMS has the status: | B. Pending |
| 4 | Who can publish articles in the project CMS? | B. Moderators and administrators |
| 5 | Which of these is a PHP-based CMS? | A. WordPress |
Project 1 : Mini CMS with PHP & MySQLi : Project – A Mini Content Management System with PHP and MySQLi
Read the notes, run the programs & take the MCQ test »
MCQ Answer Key
| No. | Question | Correct Answer |
|---|---|---|
| 1 | In the project, an access_level of 2 means: | C. Moderator |
| 2 | A newly composed article is stored with: | B. is_published = 0 |
| 3 | Which function protects pages by role in the project? | C. require_level() |
| 4 | What prevents a comment from being posted twice when the page is refreshed? | B. The Post/Redirect/Get pattern |
| 5 | Which statement publishes an article? | B. UPDATE cms_articles SET is_published = 1, publish_date = NOW() WHERE article_id = ? |