Q4 0 Notes Adv PHP
Q4 0 Notes Adv PHP
Q4 0 Notes Adv PHP
c) Write a PHP script to display server information in table format (Use $_SERVER).
Ans:- <table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<?php
foreach ($_SERVER as $key => $value) {
echo "<tr><td>$key</td><td>$value</td></tr>";
}
?>
</table>
d) What are the advantages of AJAX?
class MyClass {
public $prop1;
public function method1() {
// method code
}
}
$methods = get_class_methods('MyClass');
$vars = get_class_vars('MyClass');
print_r($methods); // Output: Array ( [0] => method1 )
print_r($vars); // Output: Array ( [prop1] => )
b) What is Inheritance? Explain with suitable example.
Example:
class Animal {
public function sound() {
echo "Animal makes a sound";
}
}
class Dog extends Animal {
public function sound() {
echo "Dog barks";
}
}
$dog = new Dog();
$dog->sound(); // Output: Dog barks
c) Explain with example how to connect database using PHP and Ajax.
Ans:- Connecting to a database using PHP and Ajax involves sending requests
from the client-side (browser) to the server-side (PHP script), which interacts with
the database and returns data asynchronously.
Example:
// PHP script (connect_db.php)
$conn = new mysqli("localhost", "username", "password", "database");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Ajax request (script.js)
$.ajax({
url: 'connect_db.php',
type: 'POST',
data: { key: 'value' },
success: function(response) {
console.log(response);
}
});
d) Explain mouse & keyboards event in JavaScript.
Ans:- Mouse & Keyboard Events in JavaScript: Mouse and keyboard
events in JavaScript allow you to respond to user interactions such as clicks, key
presses, mouse movements, etc.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Mouse & Keyboard Events</title>
</head>
<body>
<button id="myButton">Click Me</button>
<input type="text" id="myInput">
<script> document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
}); document.getElementById('myInput').addEventListener('keypress',
function(event) {
console.log('Key pressed:', event.key);
});
</script>
</body>
</html>
e) Create a XML file which gives details of books available in “Bookstore” From following
categories
i) Computer
ii) Cooking
iii) YOGA
Ans:-
<Bookstore>
<Category name="Computer">
<Book>
<Title>Introduction to Algorithms</Title>
<Author>Thomas H. Cormen</Author>
<ISBN>978-0262533058</ISBN>
</Book>
<Book>
<Title>Clean Code: A Handbook of Agile Software Craftsmanship</Title>
<Author>Robert C. Martin</Author>
<ISBN>978-0132350884</ISBN>
</Book>
</Category>
<Category name="Cooking">
<Book>
<Title>The Joy of Cooking</Title>
<Author>Irma S. Rombauer</Author>
<ISBN>978-1501174076</ISBN>
</Book>
<Book>
<Title>Mastering the Art of French Cooking</Title>
<Author>Julia Child</Author>
<ISBN>978-0241956465</ISBN>
</Book>
</Category>
<Category name="Yoga">
<Book>
<Title>The Heart of Yoga: Developing a Personal Practice</Title>
<Author>T.K.V. Desikachar</Author>
<ISBN>978-0892817641</ISBN>
</Book>
<Book>
<Title>Light on Yoga</Title>
<Author>B.K.S. Iyengar</Author>
<ISBN>978-0805210316</ISBN>
</Book>
</Category>
</Bookstore>