0% found this document useful (0 votes)
7 views16 pages

Web Technology MCQs

The document contains a comprehensive set of multiple-choice questions (MCQs) covering various topics in PHP, including basics, arrays, file handling, sessions, and cookies. Each question is followed by four answer options, with the correct answer indicated. This resource is designed for testing knowledge and understanding of PHP programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views16 pages

Web Technology MCQs

The document contains a comprehensive set of multiple-choice questions (MCQs) covering various topics in PHP, including basics, arrays, file handling, sessions, and cookies. Each question is followed by four answer options, with the correct answer indicated. This resource is designed for testing knowledge and understanding of PHP programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Question bank +Assignment

MCQs – PHP Basics


1. What does PHP stand for?
A. Personal Home Page
B. PHP: Hypertext Preprocessor
C. Private Home Page
D. Programming Home Page
Answer: B
2. Which symbol is used to define a variable in PHP?
A. @
B. #
C. $
D. %
Answer: C
3. How do you define a constant in PHP?
A. const("NAME", "value");
B. define("NAME", "value");
C. var NAME = "value";
D. constant NAME = "value";
Answer: B
4. What is the correct way to write a comment in PHP?
A. // This is a comment
B. # This is a comment
C. /* This is a comment */
D. All of the above
Answer: D
5. Which of the following is a valid PHP data type?
A. Integer
B. String
C. Boolean
D. All of the above
Answer: D
6. What will echo 5 + "5 days"; output in PHP?
A. 10
B. 55 days
C. Error
D. 5 days
Answer: A
7. Which of the following is a correct syntax to start a PHP block?
A. <?php ?>
B. <php></php>
C. <? ?>
D. Both A and C
Answer: D
8. Which operator is used for comparison in PHP?
A. =
B. ==
C. :=
D. ===
Answer: B
9. What does the === operator do in PHP?
A. Checks only value
B. Checks only data type
C. Checks value and data type
D. Assigns a value
Answer: C
10. Which loop is guaranteed to execute at least once?
A. for loop
B. while loop
C. do-while loop
D. foreach loop
Answer: C
11. Which of the following is a correct if statement in PHP?
A. if $x > 10 then {}
B. if ($x > 10) {}
C. if $x > 10 {}
D. if ($x > 10):
Answer: B

12. Which function is used to repeat execution until a condition becomes false?
A. if
B. for
C. while
D. foreach
Answer: C
13. What does the foreach loop do in PHP?
A. Loops through numbers only
B. Loops through arrays
C. Loops through strings
D. Loops through classes
Answer: B
14. In PHP, a function is defined using which keyword?
A. method
B. def
C. function
D. declare
Answer: C
15. What is the correct syntax to define a function in PHP?
A. function myFunction[] {}
B. def myFunction() {}
C. function myFunction() {}
D. myFunction() = function {}
Answer: C
16. What is call by value in PHP?
A. Original variable is changed
B. A copy of the variable is passed
C. It returns nothing
D. It is used in classes only
Answer: B
17. What is call by reference in PHP?
A. Passes only value
B. Passes address of variable
C. Cannot change original variable
D. None of the above
Answer: B
18. What keyword is used to make a function recursive?
A. recur
B. recursive
C. function calling itself
D. loop
Answer: C
19. What does the PHP strlen() function do?
A. Returns string in reverse
B. Converts to uppercase
C. Returns length of string
D. Splits string
Answer: C
20. Which function is used to replace part of a string?
A. str_replace()
B. replace()
C. substr()
D. str_repeat()
Answer: A
21. Which PHP function is used to format a string?
A. printf()
B. str_format()
C. format()
D. string_format()
Answer: A
22. What does strtoupper("php") return?
A. php
B. PHP
C. Php
D. error
Answer: B
23. Which of the following functions is used to search a string?
A. str_search()
B. strpos()
C. search_str()
D. find()
Answer: B
24. Which PHP function is used to concatenate strings?
A. concat()
B. str_concat()
C. . (dot operator)
D. +
Answer: C
25. What will echo "Hello " . "World"; output?
A. HelloWorld
B. Hello World
C. Hello . World
D. Error
Answer: B

MCQs – Arrays and Form Handling in PHP


1. What is the correct way to create an indexed array in PHP?
A. $arr = array("a" => 1, "b" => 2);
B. $arr = array(1, 2, 3);
C. array = [1 => "a", 2 => "b"];
D. int arr[] = {1,2,3};
Answer: B
2. Which of the following creates an associative array in PHP?
A. $arr = array("one", "two");
B. $arr = array(1 => "one", 2 => "two");
C. $arr = array("a" => 1, "b" => 2);
D. Both B and C
Answer: D
3. What does echo $array[0]; do?
A. Displays the whole array
B. Displays the first element of the array
C. Returns an error
D. Deletes the array
Answer: B
4. Which function is used to count the number of elements in an array?
A. sizeof()
B. count()
C. length()
D. Both A and B
Answer: D
5. Which loop is commonly used to iterate over indexed arrays?
A. foreach
B. for
C. while
D. All of the above
Answer: D
6. Which loop is best suited for associative arrays in PHP?
A. for
B. while
C. foreach
D. do-while
Answer: C
7. Which of the following functions allows both keys and values to be accessed during iteration?
A. each()
B. loop()
C. keyval()
D. access()
Answer: A
8. What does the foreach loop syntax look like?
A. foreach ($array)
B. foreach ($array => $key)
C. foreach ($array as $value)
D. foreach array as key => value
Answer: C
9. Which PHP function checks if a variable is an array?
A. is_array()
B. check_array()
C. array_check()
D. type()
Answer: A
10. What function is used to add an element to the end of an array?
A. array_push()
B. add_array()
C. insert()
D. array_add()
Answer: A
11. Which function merges two arrays?
A. array_merge()
B. merge_array()
C. combine_array()
D. append()
Answer: A
12. How do you retrieve form data using GET method in PHP?
A. $_GET['input_name']
B. $_POST['input_name']
C. $_FORM['input_name']
D. $_DATA['input_name']
Answer: A
13. How do you retrieve form data using POST method in PHP?
A. $_POST['input_name']
B. $_GET['input_name']
C. $_REQUEST['input_name']
D. Both A and C
Answer: D
14. What attribute must be set in the form tag to handle file uploads?
A. type="file"
B. enctype="multipart/form-data"
C. method="upload"
D. action="upload.php"
Answer: B
15. What global array is used to access uploaded file data?
A. $_POST
B. $_GET
C. $_FILES
D. $_UPLOADS
Answer: C
16. Which method is used to redirect a form after submission in PHP?
A. header("Location: page.php");
B. redirect("page.php");
C. location.href = "page.php";
D. go("page.php");
Answer: A
17. What superglobal is used for handling both GET and POST data?
A. $_SERVER
B. $_SESSION
C. $_REQUEST
D. $_GLOBALS
Answer: C
18. What is the correct input type for a multi-value form field (like checkboxes)?
A. <input type="multi">
B. <input type="checkbox" name="hobby[]">
C. <input type="text" name="multi">
D. <checkbox name="value[]">
Answer: B
19. What does $_FILES['file']['name'] return?
A. The size of the file
B. The type of the file
C. The name of the uploaded file
D. The temporary path
Answer: C
20. Which function moves an uploaded file to a new location?
A. file_move()
B. move_uploaded_file()
C. upload_file()
D. file_upload()
Answer: B
21. What is the default method used by an HTML form if none is specified?
A. GET
B. POST
C. PUT
D. DELETE
Answer: A
22. Which PHP array function returns all the keys of an array?
A. array_values()
B. array_keys()
C. keys()
D. get_keys()
Answer: B
23. To loop over both key and value in an associative array, which syntax is correct?
A. foreach ($array as $key => $value)
B. foreach ($array in $key => $value)
C. for ($key, $value in $array)
D. loop ($array => $key, $value)
Answer: A
24. What does reset($array) do?
A. Deletes the array
B. Resets the array pointer to the first element
C. Clears the array
D. Sorts the array
Answer: B
25. How do you check if a file was uploaded without errors?
A. $_FILES['file']['success'] == true
B. $_FILES['file']['error'] == 0
C. upload_success($_FILES['file'])
D. file_uploaded($_FILES['file'])
Answer: B

MCQs – File & Directory Handling in PHP


1. Which function is used to open a file in PHP?
A. file_open()
B. open()
C. fopen()
D. open_file()
Answer: C
2. What does the fopen() function return on failure?
A. FALSE
B. NULL
C. 0
D. Empty String
Answer: A
3. Which mode is used in fopen() to open a file for writing only?
A. r
B. w
C. rw
D. a
Answer: B
4. What does the mode 'a' mean in fopen()?
A. Append and read
B. Append only
C. Read only
D. Archive
Answer: B
5. What function is used to close an opened file?
A. file_close()
B. close()
C. fclose()
D. shut()
Answer: C
. Which function is used to read one line from a file?
A. readline()
B. freadline()
C. fgets()
D. get_line()
Answer: C
7. Which function is used to read the entire content of a file into a string?
A. read_file()
B. fread()
C. file_get_contents()
D. fgets_all()
Answer: C
8. How do you copy a file in PHP?
A. file_copy()
B. copy_file()
C. copy()
D. move_file()
Answer: C
9. Which function is used to rename a file?
A. rename()
B. file_rename()
C. mv()
D. change_name()
Answer: A
10. How can you delete a file in PHP?
A. remove()
B. delete()
C. unlink()
D. drop()
Answer: C
11. What function is used to check if a file exists?
A. exists()
B. file_exists()
C. is_file()
D. check_file()
Answer: B
12. What is the correct function to create a new directory?
A. new_folder()
B. mkdir()
C. dir_create()
D. create_folder()
Answer: B
13. What function removes an empty directory?
A. rmdir()
B. remove_dir()
C. delete_folder()
D. dropdir()
Answer: A
14. How can you open a directory in PHP?
A. open_dir()
B. fopen()
C. opendir()
D. get_dir()
Answer: C
15. Which function reads entry from a directory handle?
A. read_dir()
B. readdir()
C. get_folder()
D. fetchdir()
Answer: B
16. Which function closes a directory handle?
A. closedir()
B. dir_close()
C. folder_close()
D. shutdir()
Answer: A
17. How do you check if a path is a directory?
A. is_folder()
B. is_dir()
C. check_dir()
D. dir_exists()
Answer: B
18. Which PHP superglobal is used to handle uploaded files?
A. $_UPLOADS
B. $_FILES
C. $_FILE
D. $_POSTFILES
Answer: B
19. What function moves an uploaded file to a new location?
A. file_move()
B. move_uploaded_file()
C. upload_file()
D. rename()
Answer: B
20. Which function can be used to download a file in PHP?
A. header("Content-Disposition")
B. readfile()
C. file_download()
D. Both A and B
Answer: D
21. What header is commonly used for file downloads in PHP?
A. Content-File
B. File-Type
C. Content-Disposition
D. Content-Name
Answer: C
22. What function is used to write into a file?
A. write()
B. fwrite()
C. file_write()
D. put_file()
Answer: B
23. How do you read an entire file into an array line-by-line?
A. read_file_lines()
B. file_to_array()
C. file()
D. read_array()
Answer: C
24. Which file mode opens a file for reading and writing from the beginning?
A. r+
B. w+
C. a+
D. rw
Answer: A
25. Which function gets information about a file?
A. file_info()
B. stat()
C. file_details()
D. finfo()
Answer: B

✅ MCQs – Session and Cookie in PHP


1. What is a session in PHP used for?
A. Storing data temporarily on the server
B. Storing data permanently in the database
C. Storing data in browser cache
D. Encrypting data
Answer: A
2. Which function is used to start a session in PHP?
A. session_start()
B. start_session()
C. begin_session()
D. init_session()
Answer: A
3. Where is session data stored by default in PHP?
A. Client’s browser
B. Server
C. Cookies
D. LocalStorage
Answer: B
4. Which superglobal array is used to store session variables?
A. $_SESSION
B. $_SESSION_VAR
C. $_SESSIONDATA
D. $_SESS
Answer: A
5. What function is used to destroy a session completely?
A. session_kill()
B. destroy_session()
C. session_destroy()
D. unset_session()
Answer: C
6. Which of the following sets a session variable?
A. $_SESSION["name"] = "John";
B. $SESSION["name"] = "John";
C. session["name"] = "John";
D. set_session("name", "John");
Answer: A
7. Which function is used to unset a specific session variable?
A. session_remove()
B. unset($_SESSION['var'])
C. remove_session_var()
D. session_unset('var')
Answer: B
8. What is the default lifetime of a PHP session if not set manually?
A. 10 minutes
B. Until the browser is closed
C. 1 hour
D. 24 hours
Answer: B
9. What is a cookie in PHP?
A. A session alternative stored on the server
B. A small file stored in the browser
C. A database record
D. A PHP configuration file
Answer: B
10. Which function is used to set a cookie in PHP?
A. cookie_set()
B. setcookie()
C. make_cookie()
D. store_cookie()
Answer: B
11. What superglobal is used to access cookies?
A. $_COOKIE
B. $_COOKIES
C. $_BROWSER
D. $_HTTP_COOKIE
Answer: A
2. What is the maximum size of a cookie?
A. 2 KB
B. 4 KB
C. 10 KB
D. Unlimited
Answer: B
13. Cookies are stored on:
A. Server
B. Browser
C. Database
D. PHP Configuration File
Answer: B
4. How do you delete a cookie in PHP?
A. deletecookie("user");
B. unset($_COOKIE["user"]);
C. setcookie("user", "", time() - 3600);
D. remove_cookie("user");
Answer: C
15. Which of the following can cookies not store?
A. Text
B. Integers
C. Arrays or Objects directly
D. Booleans
Answer: C
16. Which function is used to register session variables in older PHP versions (deprecated)?
A. session_register()
B. register_session_var()
C. session_var()
D. set_session_variable()
Answer: A
17. How do you check if a session variable is set?
A. isset($_SESSION['var'])
B. isdefined($_SESSION['var'])
C. defined($_SESSION['var'])
D. isset_session('var')
Answer: A
8. What is required before using any session function in PHP?
A. HTML structure
B. Including session.php
C. Calling session_start()
D. Echoing a variable
Answer: C
19. How many cookies can a website generally store per domain?
A. 5
B. 10
C. 20
D. 50
Answer: C
20. What header must not be sent before using setcookie()?
A. Content-Disposition
B. Content-Type
C. HTTP headers
D. Any output (echo/print)
Answer: D
21. Can you access cookie values on the first page they are set?
A. Yes
B. No
C. Only in JavaScript
D. Only after 5 seconds
Answer: B
2. Which method allows using both cookies and session data together?
A. session_cookie()
B. Combining $_SESSION and $_COOKIE
C. dual_session()
D. cookie_session_combine()
Answer: B
23. What is a session ID used for?
A. Identifying browser type
B. Tracking user’s location
C. Uniquely identifying a session
D. Encrypting passwords
Answer: C
24. Which function retrieves the current session ID?
A. session_id()
B. get_session_id()
C. current_session()
D. session_key()
Answer: A
25. Which of the following helps maintain state across multiple pages in PHP?
A. GET method
B. POST method
C. Cookies and Sessions
D. HTML forms
Answer: C

✅ MCQs – MySQL and Exception Handling in PHP


1. What does RDBMS stand for?
A. Relational Data Base Managing System
B. Relational Database Management System
C. Real Database Management Syntax
D. Random Database Management System
Answer: B
2. Which PHP function is used to connect to a MySQL database?
A. mysql_connect()
B. mysqli_connect()
C. connect_mysql()
D. open_mysql()
Answer: B
3. Which of the following is not a DML statement?
A. INSERT
B. UPDATE
C. DELETE
D. CREATE
Answer: D
4. What is the correct syntax for inserting data into a MySQL table?
A. INSERT INTO table VALUES ();
B. INSERT table VALUES ();
C. INSERT DATA INTO table ();
D. ADD INTO table ();
Answer: A
. Which keyword is used to remove records from a table?
A. ERASE
B. DELETE
C. REMOVE
D. CUT
Answer: B
6. What does the SELECT statement do?
A. Deletes data
B. Modifies table structure
C. Retrieves data
D. Creates database
Answer: C
7. Which function executes a MySQL query in PHP (MySQLi)?
A. query_exec()
B. mysqli_query()
C. run_query()
D. mysql_run()
Answer: B
8. How do you fetch a result row as an associative array in PHP?
A. mysqli_fetch_assoc()
B. mysqli_get_array()
C. fetch_array()
D. mysql_fetch()
Answer: A
9. Which of the following is a type of SQL join?
A. Inline join
B. Cross join
C. Full link join
D. Merge join
Answer: B
10. What does an INNER JOIN do?
A. Returns unmatched rows
B. Returns all rows
C. Returns matching rows from both tables
D. Returns duplicate rows
Answer: C
11. What is a CROSS JOIN?
A. Filters duplicate rows
B. Matches based on condition
C. Combines all rows from both tables
D. Deletes common data
Answer: C
12. Which join returns all rows from the left table and matched rows from the right table?
A. INNER JOIN
B. RIGHT JOIN
C. FULL JOIN
D. LEFT JOIN
Answer: D
3. What is a self join?
A. Joining table with another database
B. Joining a table with itself
C. Joining with an empty table
D. It’s not a valid join
Answer: B
4. What is the default port number for MySQL?
A. 80
B. 21
C. 3306
D. 1433
Answer: C
15. Which MySQL clause is used to filter records?
A. FROM
B. WHERE
C. FILTER
D. SELECT
Answer: B
6. Which function is used to close a MySQLi connection in PHP?
A. mysqli_close()
B. mysql_shutdown()
C. disconnect()
D. db_close()
Answer: A
17. Which statement best defines an exception?
A. A notice
B. A warning
C. A runtime error that can be caught and handled
D. A syntax error
Answer: C
8. What PHP keyword is used to handle exceptions?
A. catch
B. exception
C. try
D. All of the above
Answer: D
19. What does the try block do in PHP?
A. Prevents error execution
B. Catches errors
C. Contains code that might throw an exception
D. Logs errors
Answer: C
20. What block must follow a try block?
A. handle
B. error
C. catch
D. throw
Answer: C
21. Which keyword is used to manually trigger an exception?
A. throw
B. raise
C. error
D. trigger
Answer: A
22. How can you get the error message from an exception object?
A. $e->getText()
B. $e->error()
C. $e->getMessage()
D. $e->msg()
Answer: C
23. What does the finally block do in exception handling?
A. Executes only if no error occurs
B. Executes only if an error occurs
C. Always executes, regardless of error
D. Skips execution
Answer: C
24. What type of error cannot be handled using try-catch in PHP?
A. Notices
B. Parse errors (syntax errors)
C. Exceptions
D. Warnings
Answer: B
25. Which of the following helps in debugging PHP scripts?
A. echo
B. print_r()
C. var_dump()
D. All of the above
Answer: D

You might also like