Most Repeated Questions of MSBTE (Last 10 Years)
Subject: Web Based Application Development with PHP
1. List any four advantages of PHP.
- Open-source and free to use.
- Cross-platform compatibility (runs on various operating systems).
- Supports a wide range of databases.
- Integrates easily with HTML and CSS.
2. Define serialization.
Serialization is the process of converting a data structure or object into a format that can be stored
or transmitted and reconstructed later. In PHP, the serialize() function converts a value into a
storable representation, and unserialize() reverts it back to its original form.
3. Differentiate between GET and POST methods.
GET:
- Appends data to the URL.
- Limited amount of data can be sent.
- Data is visible in the URL.
- Suitable for non-sensitive data.
POST:
- Sends data in the request body.
- Can send large amounts of data.
- Data is not visible in the URL.
- Suitable for sensitive data.
4. Write the syntax for creating a cookie in PHP.
Syntax:
setcookie(name, value, expire, path, domain, secure, httponly);
Example:
setcookie("user", "John", time() + 3600, "/");
5. Write a PHP program using a foreach loop.
$colors = array("Red", "Green", "Blue");
foreach ($colors as $color) {
echo $color . "<br>";
6. Explain indexed and associative arrays with examples.
Indexed Array: An array with numeric indices.
$fruits = array("Apple", "Banana", "Cherry");
Associative Array: An array with named keys.
$ages = array("Peter" => 35, "Ben" => 37, "Joe" => 43);
7. Differentiate between implode() and explode() functions.
implode(): Joins array elements into a single string.
$array = array('Hello', 'World');
$string = implode(" ", $array); // "Hello World"
explode(): Splits a string into an array.
$string = "Hello World";
$array = explode(" ", $string); // ['Hello', 'World']
8. Write a program to connect PHP with MySQL.
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
echo "Connected successfully";
9. Explain the concept of overriding in PHP.
Overriding in PHP occurs when a subclass provides a specific implementation of a method that is
already defined in its parent class.
Example:
class ParentClass {
public function display() {
echo "Parent display";
class ChildClass extends ParentClass {
public function display() {
echo "Child display";
10. Explain web page validation with an example.
Web page validation ensures that user inputs meet the required criteria before processing.
Example using HTML5:
<form>
<input type="email" required>
<input type="submit">
</form>