0% found this document useful (0 votes)
73 views8 pages

WBP Question Bank CT2

The document contains a class test question bank with multiple choice and programming questions covering Object Oriented Programming concepts in PHP like inheritance, cookies, MySQL data types, classes, and use of $this. It also includes questions on session management and use of form elements.
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)
73 views8 pages

WBP Question Bank CT2

The document contains a class test question bank with multiple choice and programming questions covering Object Oriented Programming concepts in PHP like inheritance, cookies, MySQL data types, classes, and use of $this. It also includes questions on session management and use of form elements.
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/ 8

WBP (22619) Question Bank Class Test – 2

Q.1) Attempt Any FOUR


Question Marking
Question And Answer
No. Scheme

List type of Inheritance?


Ans: 1. Single Inheritance
CO3(R) a. 2. Multiple Inheritance 2 Marks
3. Multiple Inheritance( Interface )
4. Hierarchical Inheritance

Organize the process of destroy cookies?


Ans: We can destroy the cookies just by updating the expiry-time value
CO4(A) b. of the cookie by setting it to a past time using the setcookie() function. 2 Marks

Syntax: setcookie(name,time()-3600);

List any four data types in MYSQL


Ans:
Data type Size Description
Maximum 255 Fixed-length char
CHAR(size)
characters string
Maximum 255
VARCHAR(size) Variable-length string
CO5(R) c. characters 2 Marks
Maximum 65,535 Size of no of char
TEXT(size)
characters stores
( 3 bytes ) Displayed as Displayed as ‘YYYY-
DATE()
‘YYYY-MM-DD’ MM-DD’
Signed values range
INT() from - 2147483648 to - Standard integer value
2147483647

Develop a program using $this.


Ans:
<?php
class Fruit {
// Properties
CO3(A) d. public $name; 2 Marks
public $color;

// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
?>

Develop the program for delete the record


Ans:

<?php

$connect = mysqli_connect("localhost","root","","db_student") or
die(mysql_error($connect));
if ($connect) {
echo "database connect";
}else{
echo "error";
}

if(isset($_GET['id']))
{
$query= 'delete from tbl_student where id="'.$_GET['id'].'" ' ;
$result = mysqli_query($connect,$query);
CO5(A) e. 2 Marks
if($result)
{
echo '<script type="text/javascript">';
echo " alert('Record Deleted Successfully ! ');";
echo 'window.location.href = "view_records.php";';
echo '</script>';
}
else
{
echo '<script type="text/javascript">';
echo " alert('Error In Record Delete ! ');";
echo 'window.location.href = "view_reporter.php";';
echo '</script>';

}
}
?>

Define term constructor and destructor.

1.Constructor:
CO3(A) f. 2 Marks
A constructor allows you to initialize an object's properties upon creation
of the object.
If you create a __construct() function, PHP will automatically call this
function when you create an object from a class.

Notice that the construct function starts with two underscores (__)!

2. Destructor:
A destructor is called when the object is destructed or the script is
stopped or exited.

If you create a __destruct() function, PHP will automatically call this


function at the end of the script.

Notice that the destruct function starts with two underscores (__)!
Q. 2) Attempt Any THREE
Question Marking
Question And Answer
No. Scheme
4 Marks
Summarize Introspection and explain with suitable example.
•Introspection in PHP offers the useful ability to examine an
object's characteristics, such as its name, parent class (if any)
Properties, classes, interfaces and methods.
•PHP offers a large number functions that can be used to accomplish the
above task.
•Following are the functions to extract basic information about classes
such as their name, the name of their parent class etc

CO3(U)

Example:
<?php
class Test
{
function testing_one()
{
return(true);
}
function testing_two()
{
return(true);
}
function testing_three()
{
return(true);
}
//Class "Test" exist or not if (class_exists('Test'))
{
$t = new Test();
echo "The class is exist. <br>";
}
else
{
echo "Class does not exist. <br>";
}
//Access name of the class
$p= new Test();
echo "Its class name is " ,get_class($p) , "<br>";
//Aceess name of the methods/functions
$method = get_class_methods(new Test()); echo "<b>List of
Methods:</b><br>"; foreach ($method as $method_name)
{
echo "$method_name<br>";
}
?>
Output :
The class is exist.
Its class name is Test List of Methods:
testing_one
testing_two
testing_three

4 Marks
Construct PHP program for cloning of an object
(Any other correct program can be considered)
Code:-
<!DOCTYPE html>
<html>
<body>
<?php
class car {
public $color;
public $price;
function construct()
{
CO3(A)
$this->color = 'red';
$this->price = 200000;
}
}
$mycar = new car();
$mycar->color = 'blue';
$mycar->price = 500000;
$newcar = clone $mycar;
print_r($newcar);
?>
</body>
</html>
. 4 Marks

Explain session and cookie. Explain use of session start().


Ans:
Session
Session is a way to store information to be used across multiple pages,
and session stores the variables until the browser is closed. To start a
session, the session_start() function is used and to destroya session, the
session_unset() and the session_destroy() functions are used.
The session variables of a session can be accessed by using the
$_SESSION super-global variable.
Cookie
Cookie is a small piece of information stored as a file in the user's browser
by the web server. A cookie stores some data temporarily (until the
expiration date has passed).There is no Unique ID allocated for a Cookie.
The cookie data can be accessed using the
$_COOKIE super-global variable. A cookie can be set using the
setcookie() function.

Use of Session start


PHP session_start() function is used to start the session. It starts a new or
CO4(U) resumes an existing session. It returns an existing session if the session is
created already. If a session is not available, it creates and returns a new
session.
session_start() creates a session or resumes the current one basedon a
session identifier passed via a GET or POST request, or passed via a
cookie.
Example:-
<?php
session_start();
?>
<html>
<body>
<?php
$_SESSION["uname"]="Customer1";
$_SESSION["fcolor"]="RED";
echo "The session variable are set with values";
?>
</body>
</html>
Develop a student form like student name, address, email, mobile no,
date of birth using different form of input elements & apply insert
operation.
Ans:
<?php

$connect = mysqli_connect("localhost","root","","db_student") or
die(mysql_error($connect));
if ($connect) {
echo "database connect";
}else{
echo "error";
}

if (isset($_POST['submit'])) {
extract($_POST);

$insert = mysqli_query($connect,"insert into tbl_student( name, email,


address, mobile, dob) values
('".$name."','".$email."','".$address."','".$mobile."','".$dob."')") or
die(mysql_error($insert));

if ($insert) {
echo '<script>alert("insert success")</script>';
4 Marks
CO5(A) }else{
echo '<script>alert("insert error")</script>';

}
}
?>
<form method="post">
<label>NAME</label>
<input type="text" name="name" placeholder="Enter Your Name"><br>
<label>Email</label>
<input type="email" name="email" placeholder="Enter Your
Email"><br>
<label>Address</label>
<textarea cols="15" rows="5" name="address"></textarea><br>
<label>Mobile</label>
<input type="tel" maxlength="10" minlength="10" name="mobile"
placeholder="Enter Your Mobile No" pattern="[7-9]{1}[0-9]{9}" ><br>
<label>DOB</label>
<input type="date" name="dob"><br>
<input type="submit" name="submit">
</form>
Build the query for database connection
Ans:
<?php
$connect = mysqli_connect("localhost","root","","db_student") or
die(mysql_error($connect));
if ($connect) {
echo "database connect";
}else{
echo "error"; 4 Marks
}
CO5(A)
?>
1. Localhost = server
2. Root = username
3. “” = password
4. db_student = database

You might also like