List Any Four Advantages of PHP ?
List Any Four Advantages of PHP ?
Platform Independent: The PHP based developed web applications can be easily run on
any platform.
Simple and Easy: PHP is simple and easy to learn and code. The command functions of
PHP can easily learn and understood. The syntax is simple and flexible to use.
Database: It has a built-in module that is used to connect to the database easily.
Multiple databases can be integrated with PHP.
Fast: PHP is known as the fastest Programming language as compared to another.
Define Serialization.
• Serialization is a technique used by programmers to preserve their working data in a
format that can later be restored to its previous form.
• Serialization in PHP is mostly automatic, it requires little extra work from the
programmer, beyond calling the serialize() and unserialize() functions.
• Data in GET method is sent as URL parameters that are usually strings of name and
value pairs separated by ampersands (&).
POST Method:
• • This is the built in PHP super global array variable that is used to get values
submitted via HTTP POST method.
• • User entered Information is never visible in the URL query string as it is visible
in GET.
OUTPUT:-
Name : Anurag
Email : anurag.sawant@vpt.edu.in
Age : 18
Gender : Male
A session is a way to store information (in variables) to be used across multiple pages.
• Session data is stored on the server side and each Session is assigned with a unique
Session ID (SID) for that session data.
• As session data is stored on the server there is no need to send any data along with
the URL for each request to server.
• More data can be stored in session as compared with cookie because location for
storing data is a server.
• PHP stores the session data in a temporary file on the server, the location of the
temporary file is specified by the session.save_path directives in the PHP configuration
file
2. Explain Indexed and Associative Array with suitable examples.
Indexed Array :
• An array with a numeric index where values are stored linearly.
• Numeric arrays use number as access keys.
• An access key is a reference to a memory slot in an array variable.
• The access key is used whenever we want to read or assign a new value an
array element
• Example:
<?php
$name[0]="Anurag";
$name[1]="Karan";
$name[2]="Justin";
echo "Size: $name[0], $name[1] and $name[2]";
?>
OUTPUT:- Names: Anurag, Karan and Justin
Associative Array
• This type of arrays is similar to the indexed arrays but instead of linear
storage, every value can be assigned with a user-defined key of string type.
• An array with a string index where instead of linear storage, each value
can be assigned a specific key.
• Associative array differs from numeric array in the sense that associative
arrays use descriptive names for id keys.
<?php
$salary=array("Justin"=>"99999999","Anurag"=>"250000","Karan"=>"50");
echo "Justin salary: ".$salary["Justin"]."<br/>";
echo "Anurag salary: ".$salary["Anurag"]."<br/>";
echo "Karan salary: ".$salary["Karan"]."<br/>";
?>
OUTPUT:- Justin salary: 99999999 Anurag salary: 250000 Karan salary: 50
Define Introspection 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 you can use to accomplish the task.
o get_class()
o get_parent_class()
o is_subclass_of()
o get_declared_classes()
o get_class_methods()
o get_class_vars()
o interface_exists()
o method_exists()
<?php
if (class_exists('Demo'))
else
?>
unserialize() : unserialize() can use string to recreate the original variable values
i.e., converts actual data from serialized data.
Syntax : unserialize(string);
Example:
<?php
$s_data= serialize(array('Welcome', 'to', 'PHP'));
print_r($s_data . "<br>");
$us_data=unserialize($s_data);
print_r($us_data);
?>
OUTPUT:
• While accessing the data using $_SESSION variable we have to mention key in the
$_SESSION variable.
<?php
session_start();
$_SESSION['name'] = "Anurag Sawant";
echo "Name : " . $_SESSION["name"];
?>
OUTPUT:- Name : Anurag Sawant
Destroy Session.
• Session automatically gets destroyed when user quits browser.
• If someone wants to destroy the session after certain operation example after a logout
that can be done using inbuilt PHP functions.
• Example:
<?php
session_start();
$_SESSION['name'] = "Anurag Sawant";
echo "Name : " . $_SESSION["name"];
session_unset(); // remove all session variables
session_destroy(); // destroy the session
echo "Name : " . $_SESSION["name"]; // Will throw an error
?>
OUTPUT:-
Name : Anurag Sawant Notice: Undefined index: name in D:\xampp\htdocs\archives\
test.php on line 9
Name :
5. Create a Web Page using GUI Components
<html>
<head>
<title>Web Page using GUI Components</title>
</head>
<body>
<form method="get" action="">
<label for="fName">First Name</label><br>
<input name="fName" type="text"><br>
<label for="lName">Last Name</label><br>
<input name="lName" type="text"><br>
<label for="phone">Phone Number</label><br>
<input name="phone" type="number"><br>
<label for="email">Email</label><br>
<input name="email" type="email"><br>
<label for="gender">Select Your Gender</label>
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender"
value="female">Female
<br>
<label for="class">Select Your Class</label>
<select name="class">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
Explain any three datatypes used in PHP
Integer
• This data type holds only numeric values.
• Integers hold only whole numbers including positive and negative numbers, i.e.,
numbers without fractional part or decimal point.
Boolean
• • The Boolean data types represents two values, true(1) or false(0).
• • Syntax
$variableName = True/False ;
EXAMPLE: $a=True;
$b=False;
OUTPUT:
New record created successfully
3. Elaborate the Following:
i) __call() ii) mysqli_connect()
__call()
• In PHP function overloading is done with the help of magic function __call().
• Function overloading contains same function name and that function performs different task
according to number of arguments.
• For example, find the area of certain shapes where radius is given then it should return area
of circle if height and width are given then it should give area of rectangle and others.
• $name is the name of the method that is being called by the object.
• Syntax:
• Syntax:
host
It is optional and it specify the host name or IP address. In case of local server localhost is used
as a general keyword to connect local server and run the program.
username
It is optional and it specify MySQL username. In local server username is root.
password
It is optional and it specify MySQL password.
database_name
It is database name where operation perform on data. It also optional.
• Return values: