This is Not AD.
Join Our Telegram Channel To Get OUR all Material Up to Date.
Don't Worry Your All Info Will Be Secured
Home About Us Services Materials Contact Us
Home About Services Materials Contact
‹
›
Home
Home > [FY] PHP | PAPER

PHP | PAPER

1. What is Preprocessor?
--> In the context of PHP (Hypertext Preprocessor), a preprocessor is a program that processes its input data (PHP code) to produce output (HTML) that is then sent to the web browser.

2. Write full form of IIS.
--> Internet Information Services (a web server created by Microsoft).

3. What is Static Variable?
--> A static variable is a local variable that does not lose its value when the function execution is completed. It remembers its value from the previous call. (Declared using the `static` keyword).
1. Explain .htaccess File.

The .htaccess (Hypertext Access) file is a configuration file used by Apache-based web servers. It allows you to make configuration changes on a per-directory basis without editing the main server config file.

Common uses include:
- Creating custom error pages (like 404 Not Found).
- URL rewriting (making URLs SEO-friendly).
- Password-protecting specific directories.
- Redirecting users from old URLs to new ones.
1. Explain any Four Array Functions.

1. count()
Used to count all the elements in an array.
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars); // Outputs: 3


2. array_push()
Inserts one or more elements to the end of an array.
$colors = array("red", "green");
array_push($colors, "blue"); // Array now has 3 colors


3. array_pop()
Removes and returns the last element of an array.
$colors = array("red", "green", "blue");
$last = array_pop($colors); // Returns "blue"


4. array_merge()
Merges one or more arrays into one single array.
$a1 = array("red", "green");
$a2 = array("blue", "yellow");
print_r(array_merge($a1, $a2));
--- OR ---
1. Write Full form of PHP?
--> PHP: Hypertext Preprocessor (Originally: Personal Home Page).

2. Write any 2 String function.
--> 1. strlen() - Returns the length of a string.
--> 2. strtoupper() - Converts a string to uppercase.

3. FTP stands for…………..
--> File Transfer Protocol.
1. Explain Foreach Loop with Example.

The foreach loop is specifically used to loop through blocks of code for each element in an array. It is the easiest way to iterate over associative or indexed arrays.

$colors = array("red", "green", "blue");

foreach ($colors as $value) {
    echo "Color: $value 
"; }
1. Explain include(), require(), header(), die() with Example.

1. include(): Includes and evaluates a specified file. If the file is not found, it throws a Warning and the script continues.
include('header.php');

2. require(): Identical to include(), except upon failure it produces a Fatal Error and stops the script.
require('db_config.php');

3. header(): Used to send raw HTTP headers to the browser. Often used to redirect users to another page.
header("Location: dashboard.php");

4. die(): Prints a message and terminates the execution of the current script. (Equivalent to `exit()`).
$conn = mysqli_connect("localhost","root","") or die("Connection failed!");
----------
1. What is Cookie ?
--> A cookie is a small piece of data sent from a web server and stored on the user's computer by the web browser while the user is browsing.

2. What is Session ?
--> A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, session data is stored on the server securely.

3. ________ function is used to send email from inside a script.
--> The mail() function.
1. Explain $_SERVER with suitable example.

$_SERVER is a PHP superglobal array that holds information about headers, paths, and script locations. It is automatically created by the web server.

Example:
echo $_SERVER['PHP_SELF']; // Returns the filename of the currently executing script.
echo $_SERVER['SERVER_NAME']; // Returns the name of the host server (e.g., localhost).
1. Write a code to upload a file.

HTML Form (index.html):
<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
PHP Code (upload.php):
<?php
if(isset($_POST["submit"])) {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    
    // Move the uploaded file to the target directory
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
--- OR ---
1. What is Server Variable ?
--> Server variables are special variables containing environment information created by the web server (like Apache). In PHP, these are accessed using the `$_SERVER` array.

2. JSON stands for _________
--> JavaScript Object Notation.

3. AJAX stands for………….
--> Asynchronous JavaScript and XML.
1. What is PHP GD Library ?

The GD (Graphics Draw) Library is an open-source extension for PHP that allows you to create and manipulate images dynamically. It is commonly used to generate charts, graphs, thumbnails, and add watermarks to images on the fly.
1. Explain mail() with Example.

The mail() function is a built-in PHP function used to send emails directly from a script. It requires a working mail server (like Postfix or Sendmail) configured on the hosting server.

Syntax:
mail(to, subject, message, headers, parameters);

Example:
<?php
$to = "student@example.com";
$subject = "Exam Result";
$message = "Hello, you have passed the PHP exam!";
$headers = "From: admin@university.edu";

// Send email
if(mail($to, $subject, $message, $headers)) {
    echo "Email successfully sent.";
} else {
    echo "Email sending failed.";
}
?>
----------
1. Full Form of SQL.
--> Structured Query Language.

2. What is Database?
--> A database is an organized collection of structured information or data, typically stored electronically in a computer system.

3. Full Form of DML?
--> Data Manipulation Language (Commands like INSERT, UPDATE, DELETE).
1. Explain mysqli_query() with example.

The mysqli_query() function is used to perform a query (like SELECT, INSERT, UPDATE, DELETE) against a database.

Example:
$conn = mysqli_connect("localhost", "root", "", "myDB");
$sql = "INSERT INTO users (name) VALUES ('Manthan')";

if(mysqli_query($conn, $sql)) {
    echo "Record inserted successfully";
}
1. Write a PHP Code to insert records from Table.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";

// 1. Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// 2. Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

// 3. SQL Query
$sql = "INSERT INTO students (name, email, course) 
        VALUES ('Manthan', 'manthan@mail.com', 'BCA')";

// 4. Execute Query
if (mysqli_query($conn, $sql)) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

// 5. Close connection
mysqli_close($conn);
?>
--- OR ---
1. Mysqli_fetch_array() is used for ____________.
--> Fetching a result row as an associative array, a numeric array, or both.

2. Which Function is used to connect with database ?
--> mysqli_connect()

3. What is MySQL in PHP?
--> MySQL is the most popular open-source Relational Database Management System (RDBMS) used with PHP to store and manage website data.
1. Explain mysqli_error() with example.

The mysqli_error() function returns a string description of the last error for the most recent MySQLi function call. It is highly useful for debugging SQL syntax errors.

Example:
if (!mysqli_query($conn, "SELECT * FROM non_existing_table")) {
  echo("Error description: " . mysqli_error($conn));
}
1. Write a PHP Code to Display all records from Table.

<?php
$conn = mysqli_connect("localhost", "root", "", "college");

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, name, course FROM students";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row using a while loop
    while($row = mysqli_fetch_array($result)) {
        echo "ID: " . $row["id"]. " - Name: " . $row["name"]. " - Course: " . $row["course"]. "<br>";
    }
} else {
    echo "0 results found";
}

mysqli_close($conn);
?>
----------
1. What is class selector ?
--> A class selector in jQuery finds elements with a specific HTML class. It is written with a period character, followed by the class name (e.g., $(".myClass")).

2. What is jQuery ?
--> jQuery is a fast, small, and feature-rich JavaScript library. It makes HTML document traversal and manipulation, event handling, and animation much simpler.

3. Write down basic syntax of jQuery.
--> $(selector).action()
(e.g., $("p").hide() hides all paragraph elements).
1. Explain focus event with suitable example.

The focus event occurs when an element gets focus (like when selected by a mouse click or by the tab key). It is commonly used on HTML form fields.

Example:
// When input gets focus, change background to yellow
$("input").focus(function(){
  $(this).css("background-color", "yellow");
});
1. Write a Program to create show and hide effect in jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide(); // Hides paragraph
  });
  
  $("#show").click(function(){
    $("p").show(); // Shows paragraph
  });
});
</script>
</head>
<body>

<p>If you click on the "Hide" button, I will disappear.</p>
<button id="hide">Hide</button>
<button id="show">Show</button>

</body>
</html>
--- OR ---
1. The extension of jQuery file is ………………….
--> .js (Because jQuery is simply a JavaScript file).

2. What is Id selector?
--> The id selector uses the id attribute of an HTML tag to find a specific element. It is written with a hash character, followed by the id name (e.g., $("#myId")).

3. Write down basic syntax of jQuery.
--> $(selector).action()
1. Explain keyup event with suitable example.

The keyup event occurs when a keyboard key is released. It is very useful for checking input field values as the user types.

Example:
// Show the text a user types in a paragraph dynamically
$("input").keyup(function(){
  $("p").text("You are typing: " + $(this).val());
});
1. Write a Program to change background color in jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    // Changes body background color using .css()
    $("body").css("background-color", "lightblue");
  });
});
</script>
</head>
<body>

<h2>jQuery Background Color Change</h2>
<button>Change Background Color</button>

</body>
</html>
----------
1. What is OOP ?
--> Object-Oriented Programming. It is a programming paradigm based on the concept of "objects", which can contain data (attributes) and code (methods).

2. What is Class ?
--> A Class is a template, blueprint, or logical structure for objects. It defines the properties and methods that the created objects will have.

3. What is const ?
--> In PHP OOP, const is a keyword used to declare constant values inside a class that cannot be changed once they are declared.
1. What is Destructor ? Explain in detail.

A Destructor is a special magic method in PHP OOP. It is automatically called when an object is destroyed or when the script ends.

- It is created using __destruct().
- It is commonly used to clean up resources, like closing a database connection or closing open files.
- Unlike constructors, destructors cannot take arguments.
1. Write a PHP Code to Insert records with OOP.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";

// Create connection using OOP approach
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO students (name, email) VALUES ('Manthan', 'manthan@mail.com')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $conn->error;
}

$conn->close();
?>
--- OR ---
1. What is Visibility ?
--> Visibility (Access Modifiers) controls where properties and methods can be accessed. The three types are `public`, `protected`, and `private`.

2. ______ sign is use as scope Resolution Operator ?
--> The double colon ::

3. What is Object?
--> An object is a specific instance of a class. When a class is defined, no memory is allocated until an object of that class is created using the `new` keyword.
1. What is Inheritance? Explain in detail.

Inheritance is a core principle of OOP where a new class (Child/Derived Class) acquires the properties and methods of an existing class (Parent/Base Class).

- It promotes code reusability.
- In PHP, inheritance is implemented using the extends keyword.
- A child class can use all public and protected methods of the parent, and can also have its own unique methods or override parent methods.
1. Write a PHP Code to Display and Delete Records in OOP.

<?php
$conn = new mysqli("localhost", "root", "", "college");

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// === 1. Display Records ===
echo "<h3>Displaying Records:</h3>";
$sql = "SELECT id, name FROM students";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
  }
} else {
  echo "0 results";
}

// === 2. Delete Record (Deleting ID 5 as example) ===
$delete_id = 5;
$sql_delete = "DELETE FROM students WHERE id = $delete_id";

if ($conn->query($sql_delete) === TRUE) {
  echo "<br>Record with ID $delete_id deleted successfully.";
} else {
  echo "<br>Error deleting record: " . $conn->error;
}

$conn->close();
?>

No comments:

Post a Comment

Sunday, 29 March 2026

[FY] PHP | PAPER

PHP | PAPER

1. What is Preprocessor?
--> In the context of PHP (Hypertext Preprocessor), a preprocessor is a program that processes its input data (PHP code) to produce output (HTML) that is then sent to the web browser.

2. Write full form of IIS.
--> Internet Information Services (a web server created by Microsoft).

3. What is Static Variable?
--> A static variable is a local variable that does not lose its value when the function execution is completed. It remembers its value from the previous call. (Declared using the `static` keyword).
1. Explain .htaccess File.

The .htaccess (Hypertext Access) file is a configuration file used by Apache-based web servers. It allows you to make configuration changes on a per-directory basis without editing the main server config file.

Common uses include:
- Creating custom error pages (like 404 Not Found).
- URL rewriting (making URLs SEO-friendly).
- Password-protecting specific directories.
- Redirecting users from old URLs to new ones.
1. Explain any Four Array Functions.

1. count()
Used to count all the elements in an array.
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars); // Outputs: 3


2. array_push()
Inserts one or more elements to the end of an array.
$colors = array("red", "green");
array_push($colors, "blue"); // Array now has 3 colors


3. array_pop()
Removes and returns the last element of an array.
$colors = array("red", "green", "blue");
$last = array_pop($colors); // Returns "blue"


4. array_merge()
Merges one or more arrays into one single array.
$a1 = array("red", "green");
$a2 = array("blue", "yellow");
print_r(array_merge($a1, $a2));
--- OR ---
1. Write Full form of PHP?
--> PHP: Hypertext Preprocessor (Originally: Personal Home Page).

2. Write any 2 String function.
--> 1. strlen() - Returns the length of a string.
--> 2. strtoupper() - Converts a string to uppercase.

3. FTP stands for…………..
--> File Transfer Protocol.
1. Explain Foreach Loop with Example.

The foreach loop is specifically used to loop through blocks of code for each element in an array. It is the easiest way to iterate over associative or indexed arrays.

$colors = array("red", "green", "blue");

foreach ($colors as $value) {
    echo "Color: $value 
"; }
1. Explain include(), require(), header(), die() with Example.

1. include(): Includes and evaluates a specified file. If the file is not found, it throws a Warning and the script continues.
include('header.php');

2. require(): Identical to include(), except upon failure it produces a Fatal Error and stops the script.
require('db_config.php');

3. header(): Used to send raw HTTP headers to the browser. Often used to redirect users to another page.
header("Location: dashboard.php");

4. die(): Prints a message and terminates the execution of the current script. (Equivalent to `exit()`).
$conn = mysqli_connect("localhost","root","") or die("Connection failed!");
----------
1. What is Cookie ?
--> A cookie is a small piece of data sent from a web server and stored on the user's computer by the web browser while the user is browsing.

2. What is Session ?
--> A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, session data is stored on the server securely.

3. ________ function is used to send email from inside a script.
--> The mail() function.
1. Explain $_SERVER with suitable example.

$_SERVER is a PHP superglobal array that holds information about headers, paths, and script locations. It is automatically created by the web server.

Example:
echo $_SERVER['PHP_SELF']; // Returns the filename of the currently executing script.
echo $_SERVER['SERVER_NAME']; // Returns the name of the host server (e.g., localhost).
1. Write a code to upload a file.

HTML Form (index.html):
<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
PHP Code (upload.php):
<?php
if(isset($_POST["submit"])) {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    
    // Move the uploaded file to the target directory
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>
--- OR ---
1. What is Server Variable ?
--> Server variables are special variables containing environment information created by the web server (like Apache). In PHP, these are accessed using the `$_SERVER` array.

2. JSON stands for _________
--> JavaScript Object Notation.

3. AJAX stands for………….
--> Asynchronous JavaScript and XML.
1. What is PHP GD Library ?

The GD (Graphics Draw) Library is an open-source extension for PHP that allows you to create and manipulate images dynamically. It is commonly used to generate charts, graphs, thumbnails, and add watermarks to images on the fly.
1. Explain mail() with Example.

The mail() function is a built-in PHP function used to send emails directly from a script. It requires a working mail server (like Postfix or Sendmail) configured on the hosting server.

Syntax:
mail(to, subject, message, headers, parameters);

Example:
<?php
$to = "student@example.com";
$subject = "Exam Result";
$message = "Hello, you have passed the PHP exam!";
$headers = "From: admin@university.edu";

// Send email
if(mail($to, $subject, $message, $headers)) {
    echo "Email successfully sent.";
} else {
    echo "Email sending failed.";
}
?>
----------
1. Full Form of SQL.
--> Structured Query Language.

2. What is Database?
--> A database is an organized collection of structured information or data, typically stored electronically in a computer system.

3. Full Form of DML?
--> Data Manipulation Language (Commands like INSERT, UPDATE, DELETE).
1. Explain mysqli_query() with example.

The mysqli_query() function is used to perform a query (like SELECT, INSERT, UPDATE, DELETE) against a database.

Example:
$conn = mysqli_connect("localhost", "root", "", "myDB");
$sql = "INSERT INTO users (name) VALUES ('Manthan')";

if(mysqli_query($conn, $sql)) {
    echo "Record inserted successfully";
}
1. Write a PHP Code to insert records from Table.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";

// 1. Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// 2. Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

// 3. SQL Query
$sql = "INSERT INTO students (name, email, course) 
        VALUES ('Manthan', 'manthan@mail.com', 'BCA')";

// 4. Execute Query
if (mysqli_query($conn, $sql)) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

// 5. Close connection
mysqli_close($conn);
?>
--- OR ---
1. Mysqli_fetch_array() is used for ____________.
--> Fetching a result row as an associative array, a numeric array, or both.

2. Which Function is used to connect with database ?
--> mysqli_connect()

3. What is MySQL in PHP?
--> MySQL is the most popular open-source Relational Database Management System (RDBMS) used with PHP to store and manage website data.
1. Explain mysqli_error() with example.

The mysqli_error() function returns a string description of the last error for the most recent MySQLi function call. It is highly useful for debugging SQL syntax errors.

Example:
if (!mysqli_query($conn, "SELECT * FROM non_existing_table")) {
  echo("Error description: " . mysqli_error($conn));
}
1. Write a PHP Code to Display all records from Table.

<?php
$conn = mysqli_connect("localhost", "root", "", "college");

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, name, course FROM students";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row using a while loop
    while($row = mysqli_fetch_array($result)) {
        echo "ID: " . $row["id"]. " - Name: " . $row["name"]. " - Course: " . $row["course"]. "<br>";
    }
} else {
    echo "0 results found";
}

mysqli_close($conn);
?>
----------
1. What is class selector ?
--> A class selector in jQuery finds elements with a specific HTML class. It is written with a period character, followed by the class name (e.g., $(".myClass")).

2. What is jQuery ?
--> jQuery is a fast, small, and feature-rich JavaScript library. It makes HTML document traversal and manipulation, event handling, and animation much simpler.

3. Write down basic syntax of jQuery.
--> $(selector).action()
(e.g., $("p").hide() hides all paragraph elements).
1. Explain focus event with suitable example.

The focus event occurs when an element gets focus (like when selected by a mouse click or by the tab key). It is commonly used on HTML form fields.

Example:
// When input gets focus, change background to yellow
$("input").focus(function(){
  $(this).css("background-color", "yellow");
});
1. Write a Program to create show and hide effect in jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide(); // Hides paragraph
  });
  
  $("#show").click(function(){
    $("p").show(); // Shows paragraph
  });
});
</script>
</head>
<body>

<p>If you click on the "Hide" button, I will disappear.</p>
<button id="hide">Hide</button>
<button id="show">Show</button>

</body>
</html>
--- OR ---
1. The extension of jQuery file is ………………….
--> .js (Because jQuery is simply a JavaScript file).

2. What is Id selector?
--> The id selector uses the id attribute of an HTML tag to find a specific element. It is written with a hash character, followed by the id name (e.g., $("#myId")).

3. Write down basic syntax of jQuery.
--> $(selector).action()
1. Explain keyup event with suitable example.

The keyup event occurs when a keyboard key is released. It is very useful for checking input field values as the user types.

Example:
// Show the text a user types in a paragraph dynamically
$("input").keyup(function(){
  $("p").text("You are typing: " + $(this).val());
});
1. Write a Program to change background color in jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    // Changes body background color using .css()
    $("body").css("background-color", "lightblue");
  });
});
</script>
</head>
<body>

<h2>jQuery Background Color Change</h2>
<button>Change Background Color</button>

</body>
</html>
----------
1. What is OOP ?
--> Object-Oriented Programming. It is a programming paradigm based on the concept of "objects", which can contain data (attributes) and code (methods).

2. What is Class ?
--> A Class is a template, blueprint, or logical structure for objects. It defines the properties and methods that the created objects will have.

3. What is const ?
--> In PHP OOP, const is a keyword used to declare constant values inside a class that cannot be changed once they are declared.
1. What is Destructor ? Explain in detail.

A Destructor is a special magic method in PHP OOP. It is automatically called when an object is destroyed or when the script ends.

- It is created using __destruct().
- It is commonly used to clean up resources, like closing a database connection or closing open files.
- Unlike constructors, destructors cannot take arguments.
1. Write a PHP Code to Insert records with OOP.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";

// Create connection using OOP approach
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO students (name, email) VALUES ('Manthan', 'manthan@mail.com')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $conn->error;
}

$conn->close();
?>
--- OR ---
1. What is Visibility ?
--> Visibility (Access Modifiers) controls where properties and methods can be accessed. The three types are `public`, `protected`, and `private`.

2. ______ sign is use as scope Resolution Operator ?
--> The double colon ::

3. What is Object?
--> An object is a specific instance of a class. When a class is defined, no memory is allocated until an object of that class is created using the `new` keyword.
1. What is Inheritance? Explain in detail.

Inheritance is a core principle of OOP where a new class (Child/Derived Class) acquires the properties and methods of an existing class (Parent/Base Class).

- It promotes code reusability.
- In PHP, inheritance is implemented using the extends keyword.
- A child class can use all public and protected methods of the parent, and can also have its own unique methods or override parent methods.
1. Write a PHP Code to Display and Delete Records in OOP.

<?php
$conn = new mysqli("localhost", "root", "", "college");

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// === 1. Display Records ===
echo "<h3>Displaying Records:</h3>";
$sql = "SELECT id, name FROM students";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
  }
} else {
  echo "0 results";
}

// === 2. Delete Record (Deleting ID 5 as example) ===
$delete_id = 5;
$sql_delete = "DELETE FROM students WHERE id = $delete_id";

if ($conn->query($sql_delete) === TRUE) {
  echo "<br>Record with ID $delete_id deleted successfully.";
} else {
  echo "<br>Error deleting record: " . $conn->error;
}

$conn->close();
?>
GOHEL MANTHAN - March 29, 2026
‹
›
Home

Creating innovative solutions for a connected world.

Email On

manthangohel04@gmail.com

This website was designed , developed and maintenance by GOHEL MANTHAN © 2026