PHP Viva
PHP Viva
2)Comments in PHP.
Ans: Single line->// or #
Mulitple line->/* ….
*/
2. Assignment Operators
Assign values to variables.
= (Assign), +=, -=, *=
3. Comparison Operators
Compare values.
== (Equal), != (Not Equal), > (Greater), < (Less)
4. Logical Operators
Combine conditions.
&& (And), || (Or), ! (Not)
5. Increment/Decrement Operators
Increase or decrease values by 1.
++$x (Pre-increment), $x++ (Post-increment)
6. String operators
String operators are specifically designed for strings.
. -> for concatenation
.= ->for concatenation assignment
4)What is array_flip()?
Ans: The array_flip() function flips or exchanges all keys
with their associated values in an array.
Syntax – array_flip(array)
1) What is a class?
Ans: A class is a blueprint of an object. Using a class we
can create many objects. A class itself is made up of
properties and methods.
Properties are different types of data objects like numbers,
string, Boolean etc. whereas Methods are functions that
operate on the data.
2) What is an Object?
Ans: An object is an instance or occurance of a class eg.
Laptop, car etc.
3) What is $this keyword?
Ans: $this is a reserved keyword that refers to calling that
particular object. I t is usually the object to which the
method belongs.
4) What are the three levels of visisbility?
Ans:
1.Public → Accessible from anywhere.
2.Protected → Accessible within the class and by child
classes.
3.Private → Accessible only within the class where it is
defined.
6)Define Destructor.
Ans: A destructor is a special member function that is
called automatically when an object is destroyed or the
script ends. It is mainly used for cleanup tasks like closing
database connections or freeing resources.
9)What is introspection?
Ans: Introspection is the ability of a program to check
name, properties or methods.
PHP Introspection functions for examining classes=
1. class_exists()
2. get_class_methods()
3. get_class_vars()
PHP Introspection functions for examining objects=
1. is_object()
2. get_object_vars()
3. method_exists()
5) What is validation?
Ans: Validation means to check the input submitted by the
user.
1) What is MYSQL?
Ans: MYSQL is a relational database management system
(RDBMS) that is used to store & retrieve data.
Syntax = mysql_function(value,value,…..);
There are two types of functions :-
1. mysqli_connect($connect)
2. mysqli_query($connect,”SQL statement”);
2) What is database?
Ans: A database is a collection of data. The CREATE
DATABASE statement is used to create database in MYSQl.
$conn = mysqli_connect() =>creates connection
die() => fun that prints error msg and then exits
$sql=”CREATE DATABASE myDB”; =>Creates database
mysqli_query=>fun that executes sql queries
3) Ways of working with MYSQL & PHP.
Ans:
1. MySQLi (Procedural) → Simple, easy to use, specific
to MySQL.
2. PDO (PHP Data Objects) → Supports multiple
databases, secure, uses prepared statements.
4) Database Operations
Ans: mysql_query() function is used to insert, select, delete
& update record in a table.
1. Insert Data: Add data to a table.
INSERT INTO table_name (column1, column2) VALUES
('value1', 'value2');
2. Retrieve Data: Get data using a query.
SELECT * FROM table_name;
3. Update Data: Modify existing data.
UPDATE table_name SET column1='new_value' WHERE
condition;
4. Delete Data: Remove data from a table.
DELETE FROM table_name WHERE condition;
5. Create Table: Make a new table.
CREATE TABLE table_name (id INT, name VARCHAR(50));
6. Drop Table: Delete an entire table.
DROP TABLE table_name;
5) What are the datatypes in MYSQL.
Ans: Numeric, DATETIME, DATE, TIMESTAMP