Unit 4 Object Oriented concept and Database Connectivity
Object oriented programming is a computer programming model that organizes software design around objects,
rather than functions and logic. Classes and objects are the two main aspects of OOP.
Class
A class is a group of objects that share common properties and behavior. Classes are the blueprints of
objects. Using a class many objects can be created.
A class is a template for objects, and an object is an instance of class. A class is defined by using
the class keyword, followed by the name of the class and a pair of curly braces ({}). All of its properties and
methods go inside the braces. In a class, variables are called properties and functions are called methods.
<?php
class Fruit {
// properties and methods goes here...
}
?>
Object
Classes are nothing without objects. We can create multiple objects from a class. Each object has all the
properties and methods defined in the class, but they will have different property values. Objects of a class
are created using the new keyword.
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
// Properties
public $name;
public $color;
// Methods
function set_name($name) {
$this->name = $name; // int a; a=name;
}
function get_name() {
return $this->name;
}
}
$apple = new Fruit();
$banana = new Fruit();
$apple->set_name('Apple');
$banana->set_name('Banana');
echo $apple->get_name();
echo "<br>";
echo $banana->get_name();
?>
</body>
</html>
$this Keyword
In PHP, $this keyword references the current object of the class. The $this keyword allows you to access
the properties and methods of the current object within the class using the object operator (->): Syntax:
$this->property $this->method() The $this keyword is only available within a class. It doesn’t exist outside
of the class. If you attempt to use the $this outside of a class, you’ll get an error.
Access Modifier/Specifier
Properties and methods have access modifiers which control where they can be accessed.
There are three access modifiers:
• public - the property or method can be accessed from everywhere. This is default
• protected - the property or method can be accessed within the class and by classes derived from
that class
• private - the property or method can ONLY be accessed within the class
For example
<?php
class Fruit {
public $name;
protected $color;
private $weight;
}
$a= new Fruit();
echo $a->name = 'Mango'; // OK
echo $a->color = 'Yellow'; // ERROR
echo $a->weight = '300'; // ERROR
?>
Constructor
A constructor allows us to initialize an object's properties upon creation of the object.
If you create a __construct() function, PHP will automatically call this function when we create an object
from a class. Notice that the construct function starts with two underscores (__).
function __construct()
{
// initialize the object and its properties by assigning
//values
}
Example
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
public $name;
public $color;
function __construct($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
$apple = new Fruit("Apple");
echo $apple->get_name();
?>
</body>
</html>
Types of Constructor
• Default Constructor: It has no parameters, but the values to the default constructor can be passed
dynamically.
• Parameterized Constructor: It takes the parameters, and also you can pass different values to the
data members.
<?php
class Fruit {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function get_name() {
return $this->name;
}
function get_color() {
return $this->color;
}
}
$apple = new Fruit("Apple", "red");
echo $apple->get_name();
echo "<br>";
echo $apple->get_color();
?>
• Copy Constructor: It accepts the address of the other objects as a parameter.
Destructor
A destructor is called when the object is destructed or the script is stopped or exited. If you create
a __destruct() function, PHP will automatically call this function at the end of the script. The destruct
function starts with two underscores (__).
function __destruct()
{
// destroying the object or clean up resources here
}
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
public $name;
public $color;
function __construct($name) {
$this->name = $name;
}
function __destruct() {
echo "The fruit is {$this->name}.";
}
}
$a= new Fruit("Apple");
?>
</body>
</html>
Differentiate between Constructor and Destructor
Constructors Destructors
Accepts one or more arguments. No arguments are passed.
function name is __construct(). function name is __destruct()
Constructor is involved automatically when the Destructor is involved automatically when the
object is created. object is destroyed.
Used to initialize the instance of a class. Used to de-initialize objects to free up memory.
Constructors can be overloaded. Destructors cannot be overloaded.
It is called each time when object is created. It is called automatically at the time of object
deletion.
Allocates memory. It deallocates memory.
Multiple constructors can exist in a class. Only one Destructor can exist in a class.
Inheritance
Inheritance is a mechanism of acquiring the features and behaviors of a class by derived class. Inheritance is
one of the core features of object-oriented programming. It's a programming procedure that allows to reuse
code by referencing the behaviors and data of an object. In other words, a class that inherits from another
class shares all the attributes and methods of the base class. An inherited class is defined by using the
extends keyword.
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
public $name;
public $color;
public function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
public function intro() {
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
public function message() {
echo "Am I a fruit or a berry? ";
}
}
$strawberry = new Strawberry("Strawberry", "red");
$strawberry->message();
$strawberry->intro();
?>
</body>
</html>
In above example, the strawberry class is inherited from the Fruit class. This means that the Strawberry
class can use the public $name and $color properties as well as the public __construct() and intro()
methods from the Fruit class because of inheritance. The Strawberry class also has its own method:
message().
Types of inheritance
Single inheritance
In this inheritance, a derived class is created from a single base class. In the given example, Class A is the
parent class and Class B is the child class since Class B inherits the features and behavior of the parent class
A.
Multi-level inheritance
In this inheritance, a derived class is created from another derived class. In the given example, class c
inherits the properties and behavior of class B and class B inherits the properties and behavior of class A.
So, here A is the parent class of B and class B is the parent class of C. So, here class C implicitly inherits the
properties and behavior of class A along with Class B i.e. this is a multilevel of inheritance.
<?php
class A {
public function fun1() {
echo "Hello from grandparent class.<br>";
}
}
class B extends A {
public function fun2() {
echo "Hello from Parent class.<br>";
}
}
class C extends B {
public function fun3() {
echo "Hello from child class.<br>";
}
}
$c = new C();
$c->fun1();
$c->fun3();
?>
Multiple inheritance
PHP does not support multiple inheritance (where a class can inherit from more than one class directly).
Instead, it uses traits to achieve similar functionality.
In the given example, class c inherits the properties and behavior of class B and class A at the same level.
So, here Class A and Class B both are the parent classes for Class C.
Hierarchical Inheritance
In this inheritance, more than one derived class is created from a single base class and further child classes
act as parent classes for more than one child class.
In the given example, class B and class C are derived from single base class A.
<?php
class A {
public function fun1() {
echo "Hello from Parent class.<br>";
}
}
class B extends A {
public function fun2() {
echo "Hello from first child class.<br>";
}
}
class C extends A {
public function fun3() {
echo "Hello from second child class.<br>";
}
}
$obj1= new B();
$obj1->fun1();
$obj2=new C();
$obj2->fun1();
?>
Function/Method Overriding
Function overriding is a technique of overriding the same method with same parameter in parent and child
class. In function overriding, both parent and child classes should have same function name with and
number of arguments. The purpose of overriding is to change the behavior of parent class method with
child class.
It provides a specific implementation of a method in a child class that differs from the implementation in
the parent class. This means that when we call the overridden method on an object of the child class, the
child class's implementation is executed instead of the parent class's.
<?php
class P {
function display() {
echo "I am Parent Class";
}}
class C extends P {
// Overriding display method
function display() {
echo "I am Child class";
}
$p = new P;
$c= new C;
$p->display();
$c->display();
?>
Creating Database using php
The CREATE DATABASE statement is used to create a database in MySQL.
When we create a new database, we must only specify the first three arguments to the mysqli object
(servername, username and password).
Syntax:
"CREATE DATABASE database_name";
For example
<?php
$servername="localhost";
$username="root";
$password="";
$conn=mysqli_connect ($servername,$username, $password);
$sql="CREATE DATABASE dang";
$result=mysqli_query ($conn,$sql);
if($result)
{
echo"Database has been created successfully";
}
else
{
die("Cannot create database because".mysqli_error($conn));
}
?>
Creating Database Connection:
PHP provides a mysqli_connect function to open a database connection. This function takes four
parameters and returns a MySQL link identifier on success or FALSE on failure.
Syntax:
connection= mysqli_connect(server, user, password, dname);
• server -The hostname running database server. If not specified then the default value is localhost.
• user - The username accessing the database. If not specified then the default is the name of the
user that owns the server is root in xampp.
• password Optional - The password of the user accessing the database. If not specified then default
Is an empty password.
• dname – it identifies the database name which we want to connect.
For Example:
dbcon.php
<?php
$servername="localhost";
$username="root";
$password="";
$dname="dbs";
$conn=mysqli_connect($servername,$username, $password,$dname);
if($conn)
{ echo"Connection OK";
}else
{
die("Connection Failed because".mysqli_connect_error());
}
?>
Creating Table using php creating table using php
The CREATE TABLE statement is used to create a table in MySQL.
Syntax:
CREATE TABLE ` TABLE_NAME` (
`field1` datatype(field_size), `field2` datatype(field_size),
`field3` datatype(field_size),
PRIMARY KEY(`field`))";
For example
<?php
include("dbcon.php");
$sql="CREATE TABLE `Student`
( `Rollno` INT(8) NOT NULL AUTO_INCREMENT ,
`FName` VARCHAR(15) NOT NULL ,
`LName` VARCHAR(10) NOT NULL ,
PRIMARY KEY (`Rollno`))";
$result=mysqli_query($conn, $sql);
if ($result) {
echo "Table created successfully";
} else {
echo "Error creating table because:::--- " . mysqli_error($conn);
}
?>
Inserting Data
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
OR
INSERT INTO table_name VALUES (value1, value2, value3,...)
For Example
<?php
include("dbcon.php");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$rn=$_POST["roll"];
$fn=$_POST["fname"];
$ln=$_POST["lname"];
$query="INSERT INTO student values('$rn','$fn','$ln')";
if(mysqli_query($conn,$query))
{
echo"
<script> alert('Data has been successfully Inserted')</script>
";
}
}
?>
<html>
<head>
</head>
<body>
<form action="" method="POST">
Rollno:
<input type="text" name="roll" value=""> <br><br>
FName:
<input type="text" name="fname" value=""><br><br>
LName:
<input type="text" name="lname" value=""><br><br>
<input type="submit" name="submit" value="Submit">
<form>
</body>
</html>
Displaying data
<?php
include("dbcon.php");
//error_reporting(0);
$query="SELECT * FROM `student`";
$data=mysqli_query($conn,$query);
?>
<html>
<table>
<tr>
<th>Rollno</th>
<th>FName</th>
<th>LName</th>
</tr>
<?php
while($result=mysqli_fetch_assoc($data))
{
echo "<tr>
<td>" .$result["Rollno"]."</td>
<td>".$result["FName"]."</td>
<td>".$result["LName"]."</td>
</tr>";
}
?>
</table>
</html>
Unit 5 AJAX and XML
Introduction to AJAX
AJAX is an acronym/stands for Asynchronous JavaScript and XML. It is a group of inter-related
technologies like JavaScript, XML, HTML/XHTML, CSS, XMLHttpRequest etc. AJAX allows to send and
receive data without reloading the web page. So it is fast.
AJAX allows to send only important information to the server not the entire page. So only
valuable data from the client side is routed to the server side. It makes the application interactive and
faster. There are too many web applications running on the web that are using ajax technology
like gmail, facebook,twitter, google map, youtube etc.
Types of AJaX
- Asynchronous Ajax: Asynchronous AJAX call allow the next line of code to execute.
-Synchronous Ajax: synchronous AJAX call stop Javascript execution until the response from the server.
How AJaX work?
As you can see in the above example, XMLHttpRequest object plays important role.
1. User sends a request from the UI and a javascript call goes to XMLHttpRequest object.
2. HTTP Request is sent to the server by XMLHttpRequest object.
3. Server interacts with the database using JSP, PHP, Servlet, ASP.net etc.
4. Data is retrieved.
5. Server sends XML data or JSON data to the XMLHttpRequest callback function.
6. HTML and CSS data is displayed on the browser.
Introduction to XML
XML is a markup language which is used for storing and transporting data. XML doesn’t depend on the
platform and the software (programming language).
o Xml (eXtensible Markup Language) is a markup language.
o XML is designed to store and transport data.
o Xml was released in late 90’s. it was created to provide an easy to use and store self-describing
data.
o XML became a W3C Recommendation on February 10, 1998.
o XML is not a replacement for HTML.
o XML is designed to be self-descriptive.
o XML is designed to carry data, not to display data.
o XML tags are not predefined. You must define your own tags.
o XML is platform independent.
XML Naming Rules
XML elements must follow these naming rules:
• Element names are case-sensitive
• Element names must start with a letter or underscore
• Element names cannot start with the letters xml (or XML, or Xml, etc)
• Element names can contain letters, digits, hyphens, underscores, and periods
• Element names cannot contain spaces
Any name can be used, no words are reserved (except xml).
XML Syntax Rules
The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
• XML Documents Must Have a Root Element
• XML documents must contain one root element that is the parent of all other elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Ram</to>
<from>Hari</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
In above example <note> is the root element:
The XML Prolog
This line is called the XML prolog:
<?xml version="1.0" encoding="UTF-8"?>
The XML prolog is optional. If it exists, it must come first in the document.
XML Element
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain:
• text
• attributes
• other elements
• or a mix of the above
<bookstore>
<book category="Networking">
<title>Harry Potter</title>
<price>2999</price>
</book>
<book category="web">
<title>Learning XML</title>
<price>3995</price>
</book>
</bookstore>
XML Attributes
XML elements can have attributes, just like HTML. Attributes are designed to contain data related to a
specific element. Attribute values must always be quoted. Either single or double quotes can be used.
Example 1
<person gender="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
Example 2
<person>
<gender>female</gender>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
In the first example, gender is an attribute. In the last example, gender is an element. Both examples
provide the same information.
Structure of XML document
XML documents form a tree structure that starts at "the root" and branches to "the leaves".
Each XML document has both: a logical and a physical structure.
Logical Structure
The logical structure of an XML document refers to the hierarchical and semantic organization of the data
within the document. The logical structure of an XML document gives information about the elements and
the order in which they are to be included in the document. It shows how a document is constructed
rather than what it contains.
Document Prolog forms the basis of the logical structure of the XML document. It contains the
following components.
• XML Declaration:- Gives the version of the XML specification and also identifies the character
encoding scheme.
Example: <?xml version=”1.0” encoding=”UTF-8”?>
• DTD: Defines a set of rules to which the XML document conforms.
The document is composed of:
• declarations,
• elements,
• and comments,
Physical Structure
The physical structure of an XML document is composed of all the content used in that document.
Physical Structure refers to the actual representation of XML data in a file, including encoding, tags,
whitespace, comments, and processing instructions.
An XML document may consist of one or many storage units, called entities. An entity can be part of the
document or external to the document.
The XML Recommendation states that an XML document has both logical and physical structure. Physically,
it is comprised of storage units called entities, each of which may refer to other entities, similar to the way
that include works in the C language.
DTD (Document Type Definition)
The XML Document Type Declaration, commonly known as DTD, is a way to describe XML language
precisely. A DTD defines the structure and the legal elements and attributes of an XML document. DTDs
check validity of the structure of XML documents against grammatical rules of appropriate XML language.
An XML DTD can be either specified inside the document, or it can be kept in a separate document and
then linked separately.
Syntax
Basic syntax of a DTD is as follows −
<!DOCTYPE element DTD identifier
[
declaration1
declaration2
........
]>
In the above syntax,
• The DTD starts with <!DOCTYPE delimiter.
• An element tells the parser to parse the document from the specified root element.
• DTD identifier is an identifier for the document type definition, which may be the path to a file on
the system or URL to a file on the internet. If the DTD is pointing to external path, it is
called External Subset.
• The square brackets [ ] enclose an optional list of entity declarations called Internal Subset.
Internal DTD
A DTD is referred to as an internal DTD if elements are declared within the XML files. To refer it as internal
DTD, standalone attribute in XML declaration must be set to yes. This means, the declaration works
independent of an external source.
Syntax
Following is the syntax of internal DTD −
<!DOCTYPE root-element [element-declarations]>
where root-element is the name of root element and element-declarations is where you declare the
elements.
Example
Following is a simple example of internal DTD −
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<!DOCTYPE address [
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
]>
<address>
<name>Ram</name>
<company>ABC</company>
<phone>980000</phone>
</address>
External DTD
In external DTD elements are declared outside the XML file. They are accessed by specifying the SYSTEM
attributes which may be either the legal .dtd file or a valid URL. To refer it as external
DTD, standalone attribute in the XML declaration must be set as no. This means, declaration includes
information from the external source.
Syntax
Following is the syntax for external DTD −
<!DOCTYPE root-element SYSTEM "file-name">
where file-name is the file with .dtd extension.
Example
The following example shows external DTD usage −
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>
The content of the DTD file address.dtd is as shown −
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
XML Namespace
In XML, element names are defined by the developer. This often results in a conflict when trying to mix
XML documents from different XML applications. XML Namespaces provide a method to avoid element
name conflicts.
Name conflicts in XML can easily be avoided using a name prefix. When using prefixes in XML,
a namespace for the prefix must be defined.
The namespace can be defined by an xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3schools.com/furniture">
<f:tr>
<f:td>Mango</f:td>
</f:tr>
</f:table>
</root>
XML Schema: It is commonly known as XML Schema Definition (XSD). It is used to describe & validate the
structure and content of XML data. It is a method of expressing constraints/limitation about xml
documents. It is like DTD but provides more control on XML structure.
Syntax: <xs:schema xmlns:xs=” “>
Definition types
a. Simple Type: used only the content of the text. It does not contain any child elements information.
for eg: xs: int, xs:string
<xs:element name=”phpno” type=”xs:int”/>
b. Complex Type: it is the container for other element definitions. It allows to specify which child
elements an element can contain & provide some structure within xml document.
for eg: save with .xsd extension
<?xml version=”1.0” encoding=”UTF-8”?>
<xs:schema xmlns:xs=”schema…”>
<xs:element name=”address”>
<xs:complextype>
<xs:sequence>
<xs:element name="email" type="xs:string"/>
<xs:element name=”name” type=”xs:string”/>
<xs:element name=”phone” type=”xs:int”/>
</xs:sequence>
</xs:complex type>
</xs:element>
</xs:schema>
add.xml
<?xml version=”1.0” encoding=”UTF-8”?>
<address>
<name>Aman</name>
<phone> 9810</phone>
<email>abc@gmail.com</email>
</address>
XSLT: XSL (eXtensible Stylesheet Language) is a styling language for XML. XSLT stands for XSL
Transformations. It is used to transform an XML document into another XML document or another
document type. It is used to define the transformation rules to be applied on the target XML document.
The XSLT processor takes the XSLT stylesheet and applies the transformation rules on the target XML
document and then it generates a formatted document in the form of XML, HTML, or text format.
For example: Transforming XML into XHTML using XSLT.
XML file:
<?xml-stylesheet type=”text/xsl” href=”simple.xsl”>
<college>
<class>
<name>Mahes</name>
<rollno>1</rollno>
</class>
</college>
Simple.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h3> Student Table</h3>
<table border="1">
<tr>
<th>Name</th>
<th>Rollno</th>
</tr>
<xsl:for-each select="college/class">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="rollno"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Element content models
Elements content models in XML defines the structure and relationships of elements within an xml
document. They specify how different elements can be combined and nested.
Element Sequences:
It specifies a particular order and count of child elements.
For example: <!ELEMENT counting(first, second, third, fourth)>
This means that the <counting> element must contain child elements in the order of<first>, <second>,
<third> and <fourth>
Element Choices
It specifies that only one of the listed elements can appear. This is done using the
pipe(|) symbol. For example:
<!ELEMENT choice(this.one | that.one)
<!ELEMENT parent (child1 | child2)>
In this case, parent can contain either child1 or child2, but not both.
Combined Sequences and Choices:
It is used to create more complex content models. For example:
<!ELEMENT parent((child1, child2) | ( child3,child4))>
In above example, the parent element can contain either a sequence of <child1> or
<child2> or a sequence of <child3> and <child4>.
<!ELEMENT parent((<fname>,<lname>) | (<email>,<password>)
Element Occurrence Indicators
In XML (eXtensible Markup Language), element occurrence indicators are used to
define how many times an element can appear within its parent element in an XML
schema or Document Type Definition (DTD). These indicators help to implement the
rules about the structure of XML documents. The two primary methods for specifying
element occurrence in XML are through XML Schema (XSD) and DTDs.
• Question mark(?)
The question mark indicates that the element is optional and may occur zero or
one time within its parent element.
Example:
<!DOCTYPE parent [
<!ELEMENT parent (childelement?)>
]>
In this example, childelement can occur zero or one time within its parent.
• Asterisk Sign(*):
The asterisk sign indicates that the element can occur zero or more time within
its parent element.
Example:
<!DOCTYPE parent [
<!ELEMENT parent (child*)>
]>
In this example, element can occur zero or more time within its parent.
• Plus Sign(+):
The plus sign indicates that the element must occur one or more times within its
parent element.
Example:
<!DOCTYPE parent [
<!ELEMENT parent (child+)>
]>
In this example, element must contain at least one child and can have more.
Unit 6 PHP Framework
Introduction
A PHP framework is a platform which allows a web developer to develop the web application. In simple
words, it provides a structure to develop web application. These frameworks save lots of time, stop
rewriting the repeated code and provide rapid application development (RAD). PHP frameworks help the
developers to rapid development of application by providing the structure.
Frameworks provide various features that facilitates the development team to build faster and cleaner
application. They often provide toolsets for both the UI components and the database access. For
examples:
Laravel
Laravel is an open-source web application framework released in June 2011. It is developed by Taylor
Otwell. Laravel is very popular because it handles complex web applications more securely and faster than
other frameworks. Laravel makes lots of common tasks of web projects much easier, such
as authentication, session, routing, and caching, etc.
The main goal of Laravel is to make web development easy and best for the developers without sacrificing
application functionality. It provides powerful tools which are necessary for large and robust application.
CodeIgniter
CodeIgniter is an application development framework which makes it much faster than other frameworks.
It was released on February 28, 2006, by EllisLab. It minimizes the size of code needed for a given task and
provides easy solutions to the complex coding problems.
CodeIgniter is not totally based on the MVC framework. It is one of the oldest frameworks with faster and
high performance. We can develop projects much faster than a scratch, as it provides a large set of
libraries, simple interface, and logical structure to access these libraries. It can be easily installed, and it
requires minimal user configuration.
Zend
Zend is an open-source, web application framework, which is developed on March 3, 2006. It is a collection
of 60+ packages which is available on GitHub and can be installed via composer. Zend is pure object-
oriented, which is developed on the basis of the MVC design pattern. Zend was developed in agile
methodology that helps to deliver a high-quality application to the enterprise client. IBM, Google
Microsoft, and Adobe are the partners of Zend.
Features of PHP frameworks
• Model View Controller (MVC) Architecture
• Database Support
• Speed-up Custom Web Application Development
• Protect Websites from Targeted Security Attacks
• No Need To Increase Web Development Cost
• Automate Common Web Development Tasks like caching, session management, authentication,
etc.
MVC Architecture
o MVC stands for "Model view And Controller".
o The main aim of MVC Architecture is to separate the Business logic & Application data from
the USER interface.
o The main advantage of Architecture is Reusability, Security and increasing the performance of
Application.
Model: Database operation such as fetch data or update data etc.
View: End-user GUI through which user can interact with system, i.e., HTML, CSS.
Controller: Contain Business logic and provide a link between model and view.
Model:
o The Model object knows about all the data that need to be displayed.
o The Model represents the application data and business rules that govern to an update of data.
o Model is not aware about the presentation of data and How the data will be display to the browser.
View:
o The View represents the presentation of the application.
o View object refers to the model remains same if there are any modifications in the Business logic.
o In other words, we can say that it is the responsibility of view to maintain consistency in its
presentation and the model changes.
Controller:
o Whenever the user sends a request for something, it always goes through Controller.
o A controller is responsible for intercepting the request from view and passes to the model for
appropriate action.
o After the action has been taken on the data, the controller is responsible for directly passes the
appropriate view to the user.
o In graphical user interfaces, controller and view work very closely together.
Sending email
PHP mail() function is used to send an email from localhost. This function requires three mandatory
arguments that specify the recipient's email address, the subject of the message and the actual message
additionally there are other two optional parameters.
syntax:
mail( to, subject, message, headers, parameters );
The description for each parameters.
S.N Parameter & Description
1 To
Required. Specifies the receiver / receivers of the email
2 Subject
Required. Specifies the subject of the email. This parameter cannot contain any newline
characters
3 Message
Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines
should not exceed 70 characters
4 Headers
Optional. Specifies additional headers.
5 Parameters
Optional. Specifies an additional parameter to the send mail program
As soon as the mail function is called PHP will attempt to send the email then it will return true if successful
or false if it is failed.
How To Send Mail From Localhost XAMPP Using PHP
To send mail from localhost XAMPP(client to server) using Gmail, configure XAMPP. We have to follow
following steps for the same and remove semicolon(;) for the following setting.
Go to C:\xampp\php and open the php.ini file.
Find [mail function] by pressing ctrl + f and pass the following values:
SMTP=smtp.gmail.com
smtp_port=587 or 25
sendmail_from = yourgmailid@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now, go to C:\xampp\sendmail and open the sendmail.ini file.
Find [sendmail] by pressing ctrl + f and pass the following values
smtp_server=smtp.gmail.com
smtp_port=587 or 25 //use any of them
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourgmailid@gmail.com
auth_password=Your-Gmail-Password
force_sender=yourgmailid@gmail.com(optional)
Now write the following code to send mail
<?php
$to_email = "receipient@gmail.com";
$subject = "Sending Mail";
$body = "Hi, Wagle; How are you?.";
$headers = "From: sender\'s email";
if(mail($to_email, $subject, $body, $headers))
{
echo "Email has been sent successfully.";
}
else
{
echo "Email sending failed...";
}
?>
PHP String Function
PHP provides various string functions to access and manipulate strings. Every programming language
provides some in-built functions for the manipulation of strings. Some of the basic string functions provided
by PHP are as follows:
1) PHP strtolower() function
The strtolower() function returns string in lowercase letter.
Syntax
string strtolower ( string $string )
Example
<?php
$str="Web Technology";
$str=strtolower($str);
echo $str;
?>
2) PHP strtoupper() function
The strtoupper() function returns string in uppercase letter.
Syntax
string strtoupper ( string $string )
Example
<?php
$str="Web Technology";
$str=strtoupper($str);
echo $str;
?>
3) PHP ucfirst() function
The ucfirst() function returns string converting first character into uppercase. It doesn't change the case of
other characters.
Syntax
string ucfirst ( string $str )
Example
<?php
$str="Web Technology";
$str=ucfirst($str);
echo $str;
?>
4) PHP lcfirst() function
The lcfirst() function returns string converting first character into lowercase. It doesn't change the case of
other characters.
Syntax
string lcfirst ( string $str )
Example
<?php
$str="Web Technology";
$str=lcfirst($str);
echo $str;
?>
5) PHP strrev() function
The strrev() function returns reversed string.
Syntax
string strrev ( string $string )
Example
<?php
$str="Web Technology";
$str=strrev($str);
echo $str;
?>
6) PHP strlen() function
The strlen() function returns length of the string.
Syntax
int strlen ( string $string )
Example
<?php
$str="Web Technology";
$str=strlen($str);
echo $str;
?>