0% found this document useful (0 votes)
2 views3 pages

Test Paper

Uploaded by

ramanand1a2b3c4d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Test Paper

Uploaded by

ramanand1a2b3c4d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1.

How would you retrieve all records of customers along with their corresponding orders
from the customers and orders tables based on customer IDs?

Ans . SELECT customers.name, orders.order_id


FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;

Q2. How would you insert a new record into the employees table with a name and age?
Ans . INSERT INTO employees (name, age) VALUES ('John Doe', 25);

Q3. How would you update the salary of an employee with employee ID 101 in the employees
table?

Ans. UPDATE employees


SET salary = 5000
WHERE employee_id = 101;

Q4. How can you retrieve all records from the products table and sort them by price in
descending order?

Ans. SELECT * FROM products ORDER BY price DESC;

Q5. How can you retrieve the names of employees who earn more than the average salary in
their department?

Ans. SELECT name


FROM employees e
WHERE salary > (SELECT AVG(salary)
FROM employees
WHERE department_id = e.department_id);

Q6. How can you define a function in PHP and return a value from it?

function addNumbers($a, $b) {


return $a + $b;
}
echo addNumbers(5, 10); // Output: 15
Q7. How do you connect to a MySQL database in PHP using mysqli?

$conn = new mysqli("localhost", "username", "password", "database");

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connected successfully!";
}

Q8. How can you perform a SELECT query and fetch results in PHP?

$result = $conn->query("SELECT * FROM users");


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

Q9. What is the difference between <div> and <section> in HTML?


Answer: <div> is a generic container element, while <section> is a semantic element used
to define sections of content that relate to a common theme. Using <section> improves the
accessibility and readability of your code for both browsers and screen readers.

Q10. What are the advantages of using external CSS stylesheets over inline styles?

● Answer: Using external CSS stylesheets has several advantages:


○ Separation of Concerns: Keeps content (HTML) and presentation (CSS)
separate, making it easier to manage and maintain.
○ Reusability: The same stylesheet can be linked to multiple HTML pages,
promoting consistency across a website.
○ Performance: Browsers cache external stylesheets, which can improve page
load times on subsequent visits.
Q11. What is the DOM, and how does JavaScript interact with it?

● Answer: The DOM (Document Object Model) is a programming interface for web
documents that represents the structure of a document as a tree of objects. JavaScript
interacts with the DOM by manipulating elements, attributes, and styles, allowing
developers to dynamically change the content and structure of a webpage in response to
user actions.

Q12. How do you handle errors in JavaScript?

● Answer: Errors in JavaScript can be handled using try, catch, and finally blocks.
Code that may throw an error is placed inside the try block. If an error occurs, control is
transferred to the catch block, where the error can be handled. The finally block
executes regardless of whether an error occurred, making it useful for cleanup
operations.

Q13. What are HTTP methods, and what are their typical uses in RESTful APIs?

● Answer: HTTP methods define the action to be performed on a resource in a RESTful


API. The most common methods include:
○ GET: Retrieve data from the server.
○ POST: Send data to the server to create a new resource.
○ PUT: Update an existing resource with new data.
○ DELETE: Remove a resource from the server.

Q14. What is JSON, and why is it commonly used in APIs?

● Answer: JSON (JavaScript Object Notation) is a lightweight data interchange format that
is easy for humans to read and write and easy for machines to parse and generate. It is
commonly used in APIs because it is language-agnostic, supports hierarchical data
structures, and has a smaller footprint compared to XML, making data transmission
more efficient.

You might also like