0% found this document useful (0 votes)
2 views

Advanced_PHP_Viva_Questions

The document provides advanced PHP viva questions and answers covering topics such as classes and objects, form handling, and database management with MySQL. It explains key concepts like class creation, object properties, inheritance, form data handling, and MySQL data types. Additionally, it includes examples for connecting PHP with MySQL and performing basic database operations.

Uploaded by

suraiyareeha
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 views

Advanced_PHP_Viva_Questions

The document provides advanced PHP viva questions and answers covering topics such as classes and objects, form handling, and database management with MySQL. It explains key concepts like class creation, object properties, inheritance, form data handling, and MySQL data types. Additionally, it includes examples for connecting PHP with MySQL and performing basic database operations.

Uploaded by

suraiyareeha
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/ 2

Advanced PHP Viva Questions and Answers

1. Class & Objects in PHP

Q: What is a class and an object in PHP?


A: A class is a blueprint for objects. An object is an instance of a class.
Q: How do you create and access a class and object in PHP?
A: Define a class using the 'class' keyword and create an object with 'new'.
Example:
class Car {}
$myCar = new Car();
Q: What are object properties?
A: Variables declared inside a class using visibility keywords (public, private, protected).
Q: What are object methods?
A: Functions defined inside a class to perform actions on object data.
Q: What is overloading in PHP?
A: Overloading allows dynamically creating properties/methods using magic methods like __get(),
__set().
Q: What is inheritance in PHP?
A: A class can inherit properties and methods from another class using 'extends'.
Example:
class Child extends Parent {}
Q: What is a constructor and destructor?
A: A constructor is __construct() used to initialize an object. A destructor is __destruct(), called when
the object is destroyed.

2. Form Handling in PHP

Q: How do you create an HTML form?


A: Using the <form> tag with method='GET' or 'POST'. Includes input elements.
Q: How do you handle form data in PHP?
A: Using superglobals like $_POST or $_GET.
Example: $_POST['username'];

3. Database Handling Using PHP with MySQL

Q: What is MySQL?
A: MySQL is an open-source relational database management system.
Q: What are some basic database terms?
A: - Table: collection of data in rows and columns
- Row: a single record
- Column: a field of the record
Q: What are MySQL data types?
A: - INT: Integer numbers
- VARCHAR: Variable-length strings
- DATE: Date values
- FLOAT: Decimal numbers
Q: How do you connect PHP with MySQL?
A: Using mysqli or PDO.
Example (mysqli):
$conn = new mysqli('localhost', 'user', 'pass', 'db');
Q: How do you insert data into MySQL using PHP?
A: Use SQL INSERT query.
Example:
mysqli_query($conn, "INSERT INTO table (col) VALUES ('val')");
Q: How do you retrieve data from MySQL using PHP?
A: Use SELECT query and fetch using mysqli_fetch_assoc().

You might also like