Professional Documents
Culture Documents
FUNDAMENTALS
OF
PHP
Lecture:- 1.1
Introduction to PHP
• The Script starts with “<?php” and ends with “?>”. These
tags are called “Canonical PHP tags”.
<!DOCTYPE html>
<html>
<head>
<title>Learn Vern</title>
</head>
<body>
<?php
echo (“Welcome to Learn Vern!”);
?>
</body>
</html>
• PHP Frameworks:-
• PHP CMS (Content Management System):-
Lecture:- 1.2
1. Requirement Gathering
2. Analysis and SRS (Software Requirements
Specification)
3. Designing
4. Implementation
5. Testing and Integration
6. Maintenance
Lecture:- 1.4
Client-Server Architecture
DBMS
And
MySQL
Lecture:- 2.1
What is DATA?
Lecture:- 2.4
What is DATABASE?
Microsoft Access
SQLite
MySQL
PostgreSQL
Lecture:- 2.3
Application
or DBMS Database
Website
• It is said that a DBMS act as connecting bridge between the
database and the user.
• DBMS actually understand the queries and help database
to understand the requirements.
• The basic difference between Database and DBMS is that a
database store the data and provide a method to access it
while a DBMS actually converts the queries into a
meaningful command to invoke the method used to access
the data
Types of Database
• Relational Database
• Hierarchical Database
• Network Database
• Object-oriented Database
• NoSQL Database
Relational Database
Hierarchical Database
Object-oriented Database
Lecture:- 2.4
Lecture:- 2.5
• CREATE • DROP
• ALTER • TRUNCATE
• INSERT
• UPDATE
• DELETE
• GRANT
• REVOKE
TCL(Transaction Control Language) or DTL (Data
Transaction Language)
• COMMIT
• ROLLBACK
• SAVEPOINT
DQL(Data Query Language)
• SELECT
Lecture:- 2.5
Lecture:- 2.6
SQL CONSTRAINTS
NOT NULL
o Ensures that a column cannot have a NULL value
UNIQUE
o Ensures that all values in a column are different
PRIMARY KEY
o A primary key is a field which can uniquely identify
each row in a table. And this constraint is used to
specify a field in a table as primary key. It is
combination of NOT NULL and UNIQUE.
DEFAULT
o Sets a default value for a column if no value is
specified
FOREIGN KEY
o A Foreign key is a field which can uniquely identify
each row in a another table. And this constraint is
used to specify a field as Foreign key.
CHECK
o Ensures that the values in a column satisfies a specific
condition
CREATE INDEX
o Used to create and retrieve data from the database
very quickly
Lecture:- 2.7
Lecture:- 2.8
CREATE Table
• SYNTAX:-
CREATE TABLE table_name (col1_name
col1_datatype, col2_name col2_datatype, ....);
Make structure of table “Products”
Field
prod_id prod_code name quantity Price
Name
DECIMAL(10,
Datatype INT CHAR(4) VARCHAR(50) INT
2)
• Syntax:-
The SQL INSERT INTO command is used to insert
data in MySQL table. Following is a generic syntax:
OR
Column
Values Reason
heading
• SELECT prod_id,
prod_code,
name
FROM `products`;
‘=‘ Equal to
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
Modulus
%
(Remainder)
LOGICAL Operators
• AND • OR • NOT
• Using IN:-
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
• Using OR:-
SELECT * FROM Customers
WHERE Country = 'Germany‘ OR Country = 'France‘
OR Country = 'UK');
• SELECT * FROM `products` WHERE products.name IN
(‘Blue Marker’, ‘Red Marker’, ‘Black Marker’);
• It will show the date of the row whose name is among any
of the Blue Marker, Red Marker, Black Marker
• It will show the date of the row whose name is among any
of the Blue Marker, Red Marker, Black Marker
Lecture:- 2.12
NULL and NOT NULL Conditions
• NULL is a special value, which represents “no value”,
”missing value” or “unknown value”.
• Syntax:-
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
• Example:-
Lecture:- 2.13
ORDER BY Clause
• Syntax:-
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;
• Syntax:-
SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number1, number2;
• Syntax:-
• Syntax:-
OR
• Syntax:-
• Syntax:-
SELECT expressions1
FROM table
GROUP BY expression2;
Function Description
HAVING
• HAVING is similar to WHERE, but it can operate on
GROUP BY aggregate functions, whereas WHERE
operates only on columns.
• Syntax:-
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SELECT prod_code AS ‘Product Code’, COUNT(*) AS
‘Count’, CAST(AVG(price) AS INT) AS ‘Average’ FROM
products;
• Syntax:-
UPDATE table_name
SET field1 = new_value1,
field2 = new_value2
[WHERE Clause]
DELETE Query
• Syntax:-
• Syntax:-
ALTER table_name
ADD new_column_name column_definition
[FIRST| AFTER column_name];
ALTER table_name
ADD new_column_name column_definition
[FIRST| AFTER column_name],
ADD new_column_name column_definition
[FIRST| AFTER column_name];
DESCRIBE Command
MODIFY
• Syntax:-
ALTER table_name
MODIFY column_name column_definition
[FIRST| AFTER column_name];
2. DESCRIBE `products`;
DESCRIBE `products`;
CHANGE COLUMN
• Syntax:-
ALTER table_name
CHANGE COLUMN old_name new_name
column_definition
[FIRST| AFTER column_name];
DROP COLUMN
• Syntax:-
• Syntax:-
ALTER table_name
RENAME TO new_table_name;
TRUNCATE TABLE
• Syntax:-
TRUNCATE table_name;
Lecture:- 2.17
Foreign Key
• Syntax:-
• Syntax:-
Lecture:- 2.18
MySQL Joins
• Types of Joins
• Syntax:-
SELECT column_names
FROM table 1(INNER)
JOIN table2
ON table1.columnName = table2.columnName
WHERE condition;
• SELECT *
FROM `products`
INNER JOIN `suppliers`
ON products.supplier_id = suppliers.sup_id;
• Left Join
• The LEFT JOIN selects all data from the left table whether
there are matching rows exist in the right table or not. In
case there is no matching rows from the right table found
NULLs are used for columns of the row from the right
table in the final result set.
• Syntax:-
SELECT column_names
FROM table 1
LEFT JOIN table2
ON table1.columnName = table2.columnName
WHERE condition;
• SELECT *
FROM `products`
LEFT JOIN `suppliers`
ON products.supplier_id = suppliers.sup_id;
• Right Join
SELECT column_names
FROM table 1
RIGHT JOIN table2
ON table1.columnName = table2.columnName
WHERE condition;
• SELECT *
FROM `products`
RIGHT JOIN `suppliers`
ON products.supplier_id = suppliers.sup_id;
• Full Join
• FULL JOIN or FULL OUTER JOIN returns all the records
which either have a match in the let or the right table.
• SELECT *
FROM `products`
RIGHT JOIN `suppliers`
ON products.supplier_id = suppliers.sup_id
UNION ALL
SELECT *
FROM `products`
RIGHT JOIN `suppliers`
ON products.supplier_id = suppliers.sup_id
WHERE products.prod_id
IS NULL;
Lecture:- 2.19
MySQL Views
• VIEWS are virtual table that do not store any data of their
own but display data stored in other tables.
• Advantage of View:-
• Syntax:-
MySQL Views
• Syntax:-
• Syntax:-
DROP VIEW IF EXISTS view_name;
Lecture:- 2.20
MySQL Functions
• Syntax:-
DELIMITER //
CREATE FUNCTION function_name(para1, para2,….)
RETURNS return_datatype
[NOT] DETERMINISTIC
BEGIN
Statements
END //
CREATE TABLE IF NOT EXISTS Students
(id INT UNSIGNED NOT NULL AUTO_INCREMENT,
fname VARCHAR(50) NOT NULL,
lname VARCHAR(50) NOT NULL,
class CHAR(4) NOT NULL,
age INT NOT NULL,
marks INT NOT NULL,
PRIMARY KEY(id));
SELECT
CONCAT(fname, ' ', lname) AS 'Name',
class, age, marks,
marksfunction(marks) AS 'Performance'
FROM students;
Lecture:- 2.21
MySQL Procedure
Creating a Procedure
• Syntax:-
DELIMITER //
CREATE PROCEDURE procedure_name
(parameter datatype, para2 datatype)
BEGIN
Declaration_section
Executable_section
END //
DELIMITER //
CREATE PROCEDURE view_products()
BEGIN
SELECT * FROM products;
END //
• To EXECUTE Procedure
CALL view_products;
DELIMITER //
CREATE PROCEDURE insert_products (IN
p_prod_code CHAR(4), IN p_name VARCHAR(50), IN
p_quantity INT(10), IN p_price DECIMAL(10,2))
BEGIN
INSERT INTO
products(prod_code,name,quantity,price) VALUES
(p_prod_code,p_name,p_quantity,p_price);
END//
ALTER TABLE `products` CHANGE `supplier_id`
`supplier_id` INT(10) UNSIGNED NULL;
• To EXECUTE Procedure
DROP PROCEDURE
MySQL Trigger
DELIMITER //
CREATE TRIGGER trigger_name
{BEFORE | AFTER}
{INSERT | UPDATE | DELETE}
ON table_name
FOR EACH ROW trigger_body;
END //
Normalization