Answer Key (WBP)
Answer Key (WBP)
c) Define Serialization.
It is a technique used by programmers to preserve there working data in specific format
that can later be restore to its previous format. Serializing an object means converting
it to a byte stream representation that can be stored into a file for that serialize() method
is used.
Syntax: serialize(value)
POST method: Information sent from a form with the post method is invisible to others
(all names/values are embedded within the body of the HTTP request). Cannot be
bookmarked and cached. POST has no limits on the amount of information to send.
g) State the use of “$” sign in PHP
The “$” sign is used for declaring a variable in PHP.
Example: $name= "Amrutvahini"
}
class demo1 extends demo
{
function display()
{
}
}
if(class_exists("demo")){
echo "Demo Class exists <br>";
}
else {
echo "Class does not exists";
}
$obj=new demo1();
echo "Class Name:";
echo get_class($obj);
echo "<br> Parent Class Name: ";
echo get_parent_class($obj);
echo "<br> Methods: ";
$arr=get_class_methods("demo1");
foreach ($arr as $i) {
print $i;
}
?>
Output:
Demo Class exists
Class Name: demo1
Parent Class Name: demo
Methods: display
Delete: Data can be deleted into MySQL tables by executing SQL DELETE statement
through PHP function mysql_query().
Program:
<?php
$host="localhost:3307";
$user="root";
$pass="";
$dbname="test";
$conn=mysqli_connect($host,$user,$pass,$dbname);
if(!$conn){
die("Could not connect:".mysqli_connect_error());
}
echo "Connected Successfully";
echo "<br>";
$sql="delete from sample where id=1";
if(mysqli_query($conn,$sql)){
echo "Deleted Successfully";
}
else{
echo "Could not delete the record";
}
mysqli_close($conn);
?>
Output:
Connected Successfully
Deleted Successfully
Q4. Attempt any THREE of the following.
a) State the variable function. Explain it with example.
Variable function: PHP supports the concept of Variable function. This means that if a
variable name has parenthesis appended to it. PHP will look for a function with the
same name as whatever the variable evaluated to, it and will attempt to execute it.
Program:
<?php
function display()
{
echo "In function display()";
echo "<br>";
}
function sample(){
echo "In function sample()";
}
$a="display";
$a();
$b="sample";
$b();
?>
Output:
In function display()
In function sample()
Retrieve the query result: Data can be retrieved into MySQL tables by executing SQL
SELECT statement through PHP function mysql_query().
<?php
$host="localhost:3307";
$user="root";
$pass="";
$db="test";
$conn=mysqli_connect($host,$user,$pass,$db);
if(!$conn){
die("Database cannot connect");
}
else{
echo "Database connected<br>";
}
$sql='select * from sample';
$val=mysqli_query($conn,$sql);
if(mysqli_num_rows($val)>0){
while($row=mysqli_fetch_assoc($val)) {
echo "ID: {$row['ID']}<br>";
echo "Name: {$row['Name']}<br>";
echo "Salary: {$row['Salary']}<br>";
}}
else{
echo "No results";
}
mysqli_close($conn);
?>
Output:
Database connected
ID: 2
Name: Rajesh
Salary: 37000
ID: 3
Name: Suraj
Salary: 40000
e) Create a web page using GUI components.
<!DOCTYPE html>
<html>
<body>
<form name="f1" method="post" action="">
Enter Your Name here:<input type="text" name="name">
<br><br>
Enter Your Address Here:<textarea name="txtarea"></textarea>
<br><br>
Gender:
<input type="radio" name="rb">Male
<input type="radio" name="rb">Female
<br><br>
Hobbies:
<input type="checkbox" name="check"> Dancing
<input type="checkbox" name="check"> Playing
<input type="checkbox" name="check"> Singing
<br><br>
<input type="submit" name="Submit ">
</form>
</body>
</html>
II. mysqli_connect():
The mysqli_connect() function is used to connect with MySQL database. It returns
resource if connection is established or not.
Syntax:
mysqli_connect(server, username, password, database_name)
Program:
<?php
$host="localhost";
$user="root";
$pass="";
$conn=mysqli_connect($host,$user,$pass);
if(!$conn){
die("Could Not Connect database");
}
else{
echo "Database Connected";
}
mysqli_close($conn);
?>
Output:
Database Connected