WBP Question Bank CT2
WBP Question Bank CT2
Syntax: setcookie(name,time()-3600);
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
?>
<?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>';
}
}
?>
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.
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
$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);
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