0% found this document useful (0 votes)
485 views10 pages

CS310 Sample Paper

The document is a sample exam for a course on open source web application development using PHP, Perl, CGI, and MySQL. It contains 40 multiple choice questions testing knowledge of PHP syntax, functions, sessions, cookies, filtering, MySQL, and basic file handling. The exam is worth 60 marks and must be completed within 90 minutes.

Uploaded by

Mohsan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
485 views10 pages

CS310 Sample Paper

The document is a sample exam for a course on open source web application development using PHP, Perl, CGI, and MySQL. It contains 40 multiple choice questions testing knowledge of PHP syntax, functions, sessions, cookies, filtering, MySQL, and basic file handling. The exam is worth 60 marks and must be completed within 90 minutes.

Uploaded by

Mohsan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

Sample Paper

FINALTERM EXAMINATION
Fall 2022
CS310 - Open Source Web Application Development (PHP, PERL, CGI, MySql)

Time: 90 min
Marks: 60

Question No: 1 (Marks: 01) - Please choose the correct option


What is the correct syntax for the PHP "include" statement?
A. include {'filename'};
B. <include 'filename'>;
C. include <'filename'>;
D. include 'filename';

Question No: 2 (Marks: 01) - Please choose the correct option


What is the syntax for the PHP date() function?
A. date(format)
B. date(timestamp)
C. date(format, timestamp)
D. date(format, value, timestamp)

Question No: 3 (Marks: 01) - Please choose the correct option


What is the PHP statement to display the current date in the format of DD-MON-YYYY?
A. <?php echo date("DD-MON-YYYY"); ?>
B. <?php echo date("dd-mon-yyyy"); ?>
C. <?php echo date("d-m-y"); ?>
D. <?php echo date("d-M-Y"); ?>

Question No: 4 (Marks: 01) - Please choose the correct option


What does the PHP date() function return?
A. Current date and time of the localhost
B. Current date and time of the server
C. Current UTC time
D. All of the above

Question No: 5 (Marks: 01) - Please choose the correct option


Which function is used to create a cookie in PHP?
A. createcookie()
B. makecookie()
C. setcookie()
D. birthcookie()

Question No: 6 (Marks: 01) - Please choose the correct option


Which function is used to start a PHP session?
A. session_starts()
B. sessions_start()
C. session_start()
D. session_init()

Question No: 7 (Marks: 01) - Please choose the correct option


Which function is used to destroy all session variables in PHP?
A. session_decode()
B. session_destruct()
C. session_destroy()
D. session_finish()

Question No: 8 (Marks: 01) - Please choose the correct option


To store user data in a session, use the ______array.
A. $_SESSION
B. SYS_SESSION
C. $SESSION
D. $_SESSIONS

Question No: 9 (Marks: 01) - Please choose the correct option


Which of the following can be achieved by using sessions in PHP?
A. Storing persistent user preferences on a website
B. Saving user authentication information across different pages
C. Creating multi-page forms
D. All of the given options

Question No: 10 (Marks: 01) - Please choose the correct option


How many types of filters are available in PHP?
A. Three
B. Two
C. Five
D. Four

Question No: 11 (Marks: 01) - Please choose the correct option


What is the result of the following PHP code snippet?

<?php
$num = "123";
if (!filter_var($num, FILTER_VALIDATE_INT))
echo("Integer is not valid");
else
echo("Integer is valid");
?>

A. No output is produced
B. The string "Integer is not valid" is displayed
C. The string "Integer is valid" is displayed
D. An error occurs

Question No: 12 (Marks: 01) - Please choose the correct option


Which one of the following filters is used to filter multiple variables with the same or
different filters?
A. filter_var_array()
B. filter_var()
C. filter_input
D. filter_input_array

Question No: 13 (Marks: 01) - Please choose the correct option


MYSQL is written in which programming language?
A. PYTHON
B. C/C++
C. JAVA
D. COBOL

Question No: 14 (Marks: 01) - Please choose the correct option


What does HOST mean in MYSQL?
A. HOST is the user name.
B. HOST represents the location where the MYSQL server is running.
C. HOST is the machine name of the administrator.
D. HOST is the name of the Database Engine.

Question No: 15 (Marks: 01) - Please choose the correct option


Which of the following is full form of SQL?
A. Structured Query List
B. Structure Query Language
C. Sample Query Language
D. Sequential Query Language

Question No: 16 (Marks: 01) - Please choose the correct option


Which server cannot be used to install PHP?
A. XAMPP Server
B. WAMP Server
C. YAMP Server
D. Vertigo Server

Question No: 17 (Marks: 01) - Please choose the correct option


Which is the incorrect syntax for starting and ending a PHP code block among the
following options?
A. <?php … ?>
B. <?... ?>
C. <% … %>
D. <!-- -->

Question No: 18 (Marks: 01) - Please choose the correct option


MYSQL query results are displayed in the form of ________.
A. LIST
B. TUPLE
C. ROWS AND COLUMNS
D. BOTH LIST AND TUPLES

Question No: 19 (Marks: 01) - Please choose the correct option


What is the correct syntax for creating a table in MYSQL?
A. CREATE TABLE name;
B. CREATE name;
C. CREATE TABLE
D. All of the given options are correct

Question No: 20 (Marks: 01) - Please choose the correct option


Which database has PHP been supporting almost since its inception?
A. Oracle Database
B. SQL
C. SQL+
D. MySQL

Question No: 21 (Marks: 01) - Please choose the correct option


What is the commonly referred name of the updated MySQL extension released with
PHP 5?
A. MySQL
B. mysqi
C. mysqli
D. mysqly

Question No: 22 (Marks: 01) - Please choose the correct option


Which method can be used to display information about a MySQL connection error?
A. connect_errno()
B. connect_error()
C. mysqli_connect_errno()
D. mysqli_connect_errors()

Question No: 23 (Marks: 01) - Please choose the correct option


Which method is used to execute a statement after parameters have been bound?
A. bind_param()
B. bind_result()
C. bound_param()
D. bound_result()
Question No: 24 (Marks: 01) - Please choose the correct option
Which method is used to retrieve resources of a prepared statement?
A. end()
B. finish()
C. final()
D. close()

Question No: 25 (Marks: 01) - Please choose the correct option


Which command is used to enter data into a table?
A. SELECT
B. LOAD
C. INSERT
D. UPDATE

Question No: 26 (Marks: 01) - Please choose the correct option


What is the correct way to select data from a table?
A. SELECT row_name FROM table_name
B. SELECT column_name FROM table_name
C. SELECT table_name FROM column_name
D. SELECT row_name FROM column_name

Question No: 27 (Marks: 01) - Please choose the correct option


In the following SQL statement, what does "abc" refer to?
DELETE FROM abc WHERE xyz=10;
A. Column name
B. Row name
C. Table name
D. Database name

Question No: 28 (Marks: 01) - Please choose the correct option


In the following SQL statement, what does "xyz" refer to?
DELETE FROM abc WHERE xyz=15;
A. Column name
B. Row name
C. Table name
D. Database name

Question No: 29 (Marks: 01) - Please choose the correct option


In the UPDATE statement, which keyword is used to assign values to columns?
A. Set
B. Assign
C. Mark
D. Get

Question No: 30 (Marks: 01) - Please choose the correct option


Which PHP function is used to open a file?
A. open()
B. fopen()
C. create()
D. insert()

Question No: 31 (Marks: 01) - Please choose the correct option


How many arguments does the fopen() function require?
A. 0
B. 1
C. 2
D. 3
Question No: 32 (Marks: 01) - Please choose the correct option
Which function is used to find the length of a file in PHP?
A. fsize()
B. fcount()
C. filesize()
D. count()

Question No: 33 (Marks: 01) - Please choose the correct option


Is it necessary to close a file with the fclose() function in PHP?
A. Yes
B. No
C. Can be yes or no
D. Can not say

Question No: 34 (Marks: 01) - Please choose the correct option


In PHP, which function outputs the contents of a string variable to the specified resource?
A. filewrite()
B. fwrite()
C. filewrites()
D. fwrites()

Question No: 35 (Marks: 01) - Please choose the correct option


Which function is used to read an existing file in PHP?
A. openfile()
B. readfile()
C. readf()
D. read_f()

Question No: 36 (Marks: 01) - Please choose the correct option


Which function is used to stop the execution of a PHP script and display a message?
A. close()
B. exit_script()
C. die()
D. die_script()
Question No: 37 (Marks: 01) - Please choose the correct option
Which function is used to determine the size of a file in PHP?
A. filelen()
B. filelength()
C. filesize()
D. fsize()

Question No: 38 (Marks: 01) - Please choose the correct option


Which function is used to read a single line from a file in PHP?
A. freadline()
B. fgets()
C. fgetline()
D. fline()

Question No: 39 (Marks: 01) - Please choose the correct option


What is WordPress classified as?
A. Content Management System
B. Blogger
C. Programming language
D. All of these

Question No: 40 (Marks: 01) - Please choose the correct option


What does CMS stand for?
A. Content Management System
B. Creator Management System
C. Content Manager Source
D. Constant Manager Source

Question No: 41 (Marks: 03)


How to create and retrieve a PHP cookie in a web application?
Answer:
To create a PHP cookie in a web application, the setcookie() function is used. To obtain
the value of a PHP cookie in a web application, the $_COOKIE superglobal array is used.

Question No: 42 (Marks: 03)


Write down the names of functions used to initiate and terminate a session in PHP?
Answer:
The function to initiate a session in PHP is session_start() and the function to terminate a
session is session_destroy().

Question No: 43 (Marks: 03)


Write down the uses of “filter_var()” function used in php.
Answer:
The “filter_var” is used for:
1. Validation
2. Sanitization
3. Type Casting
4. To create custom filters

Question No: 44 (Marks: 03)


Write down three ways to work with MySQL and PHP.
Answer:
1. MySQLi (Object Oriented)
2. MySQLi (Procedural)
3. PDO (PHP Data Objects)

Question No: 45 (Marks: 03)


Fix the errors in the following PHP code to write in a file.
<?php
$file = 'mydata.txt';
$data = "Welcome to File Handling.";
$handle = open($file, 'a');
$write = write($handle, $data);

fclose($handle);
?>

Answer:
<?php
$file = 'mydata.txt';
$data = "Welcome to File Handling.";
$handle = fopen($file, 'a'); //fopen() is used to open the file
$write = fwrite($handle, $data); //fwrite() is used to write in the file
fclose($handle);
?>

Question No: 46 (Marks: 03)

What is WordPress and what kind of tasks can it help with?

Answer:
WordPress is a free and open-source content management system (CMS) designed to
make it easy for users to create, manage, and publish websites, blogs, and other types of
content. With WordPress, you can perform tasks such as writing blog posts, adding
pages, creating menus, and managing media files without needing technical knowledge or
programming skills.
Question No: 47 (Marks: 05)
Write down the PHP code to determine the existence of a text file and write “ABC” in it.
Then check data was written successfully or not then close the file.
Answer:
<?php

// Verify the existence of the text file


$file = 'mydata.txt';
if (file_exists($file)) {
echo "The text file exists.<br>";
} else {
echo "The text file does not exist.<br>";
}

// Write some data to the text file


$text = "ABC";
$handle = fopen($file, 'a');
$write = fwrite($handle, $text);

// Check if the data was written successfully


if ($write) {
echo "The data was added to the text file successfully.<br>";
} else {
echo "The data could not be added to the text file.<br>";
}

// Close the text file


fclose($handle);

?>

Question No: 48 (Marks: 05)


Write down the code to insert data into MySQL table using PHP and MySQLi extension.
Answer:
The syntax is as follows:

$conn = mysqli_connect("hostname", "username", "password", "database");


$sql = "INSERT INTO table_name (column1, column2, column3) VALUES ('value1',
'value2', 'value3')";

if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

Question No: 49 (Marks: 05)


Write down the code to create a simple login system in PHP using sessions.
Answer:
<?php
session_start();
if (isset($_POST['submitBtn'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
if ($user === "admin" && $pass === "secret") {
$_SESSION['is_logged_in'] = true;
header('Location: home.php');
exit;
}
$errorMessage = "Invalid login";
}

if (isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] === true) {


header('Location: home.php');
exit;
}
?>

Question No: 50 (Marks: 05)


Write PHP code to limit the number of rows to five returned from MYSQL query.
Answer:
<?php
$conn = new mysqli("localhost", "user", "pass", "db");
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);

$res = $conn->query("SELECT * FROM tbl LIMIT 5");


if ($res->num_rows > 0) {
while($row = $res->fetch_assoc()) {
echo "id: " . $row["id"]. " - Info: " . $row["info"]. "<br>";
}
} else echo "0 results";
$conn->close();
?>

You might also like