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

240101066_module_2 V2

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

240101066_module_2 V2

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

NAME: MAHADEV

KESHARI

ROLL NO: 240101066

2024 -2028{CSE}
MODULE:2 ASSIGNMENT

PROFESSOR NAME :
UJJAWAL BISWAS
INTRODUCTION TO PHP:
a.Why do we use PHP ?

smoother
development

cloud provide
compatibility security

resourceful 1.Why
Dynamic
community we use structure
and support
PHP

easy to use in
open sources web
development
server
support side
printing

FIG M2.1 ILLUSTRATES KEY USES OF PHP.

b.Application of PHP :-
Data
representation

Graphics
Design and Web content
image management
processing

Application
Create flash of PHP
based design web
animation based
Graphics user application
interface

E -commerece
Dash board
Application

FIG M2.2 THE DETAILS OF APPLICATION OF PHP

C.HISTORY OF PHP :-
PHP started out as a small open-source project that evolved gradually as more and more
people found out how useful it was. Rasmus Lerdorf released the first version of PHP
way back in 1994. At that time, PHP stood for Personal Home Page, as he used it to
maintain his personal homepage. Later on, he added database support and called it as
"Personal Home Page/Forms Interpreter" or PHP/FI, which could be used to build
simple, dynamic web applications.
Zeev Suraski and Andi Gutmans rewrote the parser in 1997 and formed the base of PHP
3. The name of the language was also changed to the recursive acronym PHP: Hypertext
Preprocessor. They are also the authors of Zend Engine, a compiler and runtime
environment for the PHP. Zend Engine powered PHP 4 was released in May 2000.
• PHP 5 was released in 2004, which included many new features such as OOP support, the PHP
Data Objects (PDO), and numerous performance enhancements.
• PHP 7, is a new major PHP version which was developed in 2015. It included new language
features, most notable being, the introduction of return type declarations for functions which
complement the existing parameter type declarations, and support for the scalar types (integer,
float, string, and boolean) in parameter and return type declarations.
d. Version of PHP :-

FIG M2.4 VERSIONS OF PHP


e.Environment Setup For PHP XAMP IN WINDOWS :
Various PHP frameworks such as Laravel, Symfony, and others use the PHP
environment variable itself to store different security-related credentials and other
configurations. An ENV var or environment variable is nothing but a key-value
pair used in the global scope. These variables are explicitly stored for each
environment. In other words, an environment variable can be defined as a
dynamic-named variable that is provided in a program for affecting the way
successively running processes will work in a system.
These variables are brought into the global namespace of PHP from the
environment under which the PHP runs its parser. Many of them are provided by
the shell under which PHP runs with different systems that are likely to run
different kinds of shells. Other environment variables include the CGI variables,
irrespective of whether they are running as a server module or as a CGI processor
in PHP.

FIG M2.5 ENVIRONMENT SETUP IN PHP

f.Environment Setup for php XAMP in unix


Step 1: Download the Installer for Linux.
Open a new browser window and go to the Official Apache downloads webpage.
 Move to the Linux download links sections and download the latest installer
package.
 Xampp uses “.run” shell script files to make it easy to automatically install
the package without much manual intervention.
 It also supports every major distribution like Debian, Arch, Redhat, Ubuntu,
and Manjaro.

FIG M2.6 ENVIRONMENT SETUP IN PHP

download installer for linux


Step 2: Make the installer executable
 Once the installed is downloaded, we need to run the installer, by default no
file will be given the executable permission.
 Open a new Terminal and go to the location of the installer file, most likely it
is Downloads.
 Use the chmod command with x flag to give the executable permission for the
installer using the below command.
sudo chmod +x xampp-linux-x64-8.2.12-0-installer.run
 +x is the flag used to make the file executable for everyone, if you need to
restrict the permission use “u+x” so that only the current user can execute it.

FIG.M2.7 LOCATION OF INSTRALLER FILE IN PHP

make the installed executable


Step 3: Run the Installer
 After providing the executable permission, run the installer to install the
software in the system.
 Run the installer from the same terminal with Sudo permission using the
below command.
 Sudo permission is required as by xampp uses the “/opt” directory to write
down the files.
sudo ./xampp-linux-x64-8.2.12-0-installer.run
 A new Graphical window will be popped front, we can continue the
installation process from there.
 In the below image we can see that it is requesting for further process, to
proceed with the installation click on the Forward button in the bottom of the
window.
8

FIG M2.8 REQUESTING FOR INSTALLATION IN PHP

 Here we need to select the components needs to be installed along with


Xampp. There are different components like,
o Core files
o Developer files
 If its your development machine check the developer files also, I am going
with the default options that is checked both the files.
 Click on the Forward button to proceed with the installation.
FIG M2.9 FINAL STEP FOR PHP INSTALLATION

 Xampp alerting us it will install the modules and files under


the “/opt/lampp” directory. It is the intended folder for software that is not
We can’t change the installation folder, so click on Forward button to accept
the installation directory for Xampp.
FIG M2 .10 CHANGING THE INSTALLATION FOLDER

 Now we have configured the installation and we can write the changes, so it
prompts us for final question whether it can install Xampp on the System for
the configuration.
 Click on Forward to accept the changes, in case you need to change anything
cancel it and start from the beginning.

FIG M2.11 FUTHER STEP OF PHP INSTALLATION FILE


Now the installer is writing the files of the Software to our system. It may take a
couple of minutes based on your Hardware configuration, sit back and relax until
the installation is complete.
FIG .M2.12 INSTALLING XAMP FILE

 Feel free to uncheck the Launch Xampp checkbox, we will see how we can
start Xampp in the next step.
 Finally Click on Finish to complete the Setup process.

FIG M2.13 LAUNCH XAMPP


Step 4: Start Xampp Program
 To start Xampp, either use the command line tool or the GUI manager.
 First of all move into the xampp installation folder using cd command.
cd /opt/lampp
Using Command Line tool
Use the below command to start Xampp. This will start entire Xampp program
including Apache, MysqlDB and others.
sudo ./lampp start

FIG M2.14 STARTING XAMPP PROGRAM

starting lampp with terminal


 To just start the required services refer to the help page of Xampp. It
includes options like
o startapache -> starts only apache server
o startmysql -> starts mysql
./lampp help
Using GUI Xampp Manager
To start the GUI Xampp manager, run the following command.
sudo ./manager-linux-x64.run

FIG FIRST OVERVIEW OF XAMP

running gui manager


Checking Xampp Server
 Once Xampp is started, open your browser and go to the `http://localhost/`
url.
 A welcome page of Apache server will be displayed.

final output after installation


Uninstalling Xampp in Linux
 To Uninstall Xampp, open a new terminal window and move into the
installation folder, here the “/opt/lampp” folder.
 Xampp tool ships with beginner friendly uninstaller executable, so that you
don’t have to mess with manual deletion of files and folders.
 Run the uninstall executable with sudo privilege to initiate the uninstallation
process.
 Use the below command to uninstall the program, make sure you are in the
intended directory.
sudo ./uninstall
Provide your super user password to start the process, double check you have
backed up important data before proceeding with the uninstallation.

running uninstall xampp


Click on “Yes” in the Question dialog box to proceed wit uninstallation. This will
remove entire modules of the Xampp like Apache Server, Maria DB, etc. So, think
before you act.

uninstalling xampp
In the above image, you can refer that its being uninstalled. Once the progress is
over, you can close the terminal window.
Conclusion
In this article we have seen step by step procedure of installing Xampp, a easy to
install suite of software that comes as a single package for Apache server, Maria
DB, PHP. We have also seen how to uninstall it incase we need to completely
remove the software from the System.

Three 90 Challenge is back on popular demand! After processing refunds worth


INR 1CR+, we are back with the offer if you missed it the first time. Get 90%
course fee refund in 90 days. Avail now!
Unlock the power of Linux with our Online Linux Course with Certification!
Whether a beginner or an experienced professional, this course is designed to help
you master Linux, the backbone of modern computing. Dive into comprehensive
modules covering everything from basic commands to advanced system
administration. With hands-on projects and real-world examples, you'll gain the
skills to manage Linux environments efficiently and confidently. Plus, earn a
certification that showcases your expertise to potential employers.

g. Running Hello world php script :

FIG M2 .17 RUNNING HELLO WORLD


2.Basics of PHP Script:
a. How parser engine can differentiate can differentiate PHP code ?

b.data types in PHP:


In PHP, data types are essential as they define the type of data a variable can store. PHP
supports several primitive data types that can be categorized into three main types:
Scalar Types, Compound Types, and Special Types.
Scalar Types
Scalar types in PHP are those that represent a single value. There are four scalar data
types:
 Boolean: Represents two possible states, TRUE or FALSE. It is often used in
conditional statements to represent the outcome of an expression.
 Integer: Represents whole numbers, both positive and negative, without any
decimal points. Integers can be in decimal, octal, or hexadecimal form.
 Float (or double): Represents numbers with a decimal point or in exponential
form. Unlike integers, floats can represent fractional numbers.
 String: Represents a sequence of characters and can include letters, numbers, and
special characters. Strings must be enclosed in quotes, either single or double.
c. Constant in PHP:
A constant is an identifier (name) for a simple value. The value cannot be changed
during the script.
A valid constant name starts with a letter or underscore (no $ sign before the
constant name).
Note: Unlike variables, constants are automatically global across the entire script.

Create a PHP Constant


To create a constant, use the define() function.
Syntax
define(name, value);
Parameters:
 name: Specifies the name of the constant
 value: Specifies the value of the constant

e.Variables in PHP :
In PHP, data types are essential as they define the type of data a variable can store.
PHP supports several primitive data types that can be categorized into three main
types: Scalar Types, Compound Types, and Special Types.
Scalar Types
Scalar types in PHP are those that represent a single value. There are four scalar
data types:
 Boolean: Represents two possible states, TRUE or FALSE. It is often used in
conditional statements to represent the outcome of an expression.
 Integer: Represents whole numbers, both positive and negative, without any
decimal points. Integers can be in decimal, octal, or hexadecimal form.
 Float (or double): Represents numbers with a decimal point or in exponential
form. Unlike integers, floats can represent fractional numbers.
 String: Represents a sequence of characters and can include letters, numbers,
and special characters. Strings must be enclosed in quotes, either single or
double.
e.Operators in PHP:
Operators are used to performing operations on some values. In other words, we
can describe operators as something that takes some values, performs some
operation on them, and gives a result. From example, “1 + 2 = 3” in this expression
‘+’ is an operator. It takes two values 1 and 2, performs an addition operation on
them to give 3.
Just like any other programming language, PHP also supports various types of
operations like arithmetic operations(addition, subtraction, etc), logical
operations(AND, OR etc), Increment/Decrement Operations, etc. Thus, PHP
provides us with many operators to perform such operations on various operands
or variables, or values. These operators are nothing but symbols needed to perform
operations of various types. Given below are the various groups of operators:
 Arithmetic Operators
 Logical or Relational Operators
 Comparison Operators
 Conditional or Ternary Operators
 Assignment Operators
 Spaceship Operators (Introduced in PHP 7)
 Array Operators
 Increment/Decrement Operators
 String Operators
f. String in PHP:
A string is a sequence of characters, like 'PHP supports string operations.' A string
in PHP as an array of bytes and an integer indicating the length of the buffer. In
PHP, a character is the same as a byte. This means that PHP only supports a 256-
character set, and hence does not offer native Unicode support.
PHP supports single quoted as well as double quoted string formation. Both the
representations 'this is a simple string' as well as "this is a simple string" are valid.
PHP also has Heredoc and Newdoc representations of string data type.
g.Comments in PHP :

h. Conditional statements in PHP :


A conditional statement in PHP is a programming construct that allows you to
execute different blocks of code based on whether a specified condition evaluates to
true or false. It enables you to create dynamic and flexible code logic by controlling
the flow of execution based on various conditions.
Conditional statements in PHP include:
PHP conditional statements, like if, else, elseif, and switch, control code execution
based on specified conditions, enhancing code flexibility and logic flow.

i.Loops in PHP:
3.Advanced features in PHP :
a. Array in PHP :
An array is a special variable that can hold many values under a single name, and you
can access the values by referring to an index number or name.

PHP Array Types


In PHP, there are three types of arrays:
 Indexed arrays - Arrays with a numeric index
 Associative arrays - Arrays with named keys
 Multidimensional arrays - Arrays containing one or more arrays

Working With Arrays


In this tutorial you will learn how to work with arrays, including:
 Create Arrays
 Access Arrays
 Update Arrays
 Add Array Items
 Remove Array Items
 Sort Arrays

Array Items
Array items can be of any data type.
The most common are strings and numbers (int, float), but array items can also be
objects, functions or even arrays.
You can have different data types in the same array.
b.functions in PHP:
c.Form handling in PHP:
HTML Forms play an important role in PHP web applications. Although a webpage
composed purely with HTML is a static webpage, the HTML form component is an
important feature that helps in bringing interactivity and rendering dynamic content.
PHP’s form handling functionality can validate data collected from the user, before
processing.
An HTML Form is a collection various form controls such as text fields, checkboxes,
radio buttons, etc., with which the user can interact, enter or choose certain data that
may be either locally processed by JavaScript (client-side processing), or sent to a
remote server for processing with the help of server-side programming scripts such as
PHP.
One or more form control elements are put inside <form> and </form> tags. The form
element is characterized by different attributes such as name, action, and method.
<form [attributes]>
Form controls
</form>

d.PHP mail sending script


FIGM2. 18 PHP script for file
Handling :
f. Session Handling in PHP:
When you work with an application, you open it, do some changes, and then you close
it. This is much like a Session. The computer knows who you are. It knows when you
start the application and when you end. But on the internet there is one problem: the web
server does not know who you are or what you do, because the HTTP address doesn't
maintain state.
Session variables solve this problem by storing user information to be used across
multiple pages (e.g. username, favorite color, etc). By default, session variables last until
the user closes the browser.
So; Session variables hold information about one single user, and are available to all
pages in one application.
M2 .19 Session Handling in PHP:

g.
Error & exception Handling in

PHP :
With PHP 5 came a new object oriented way of dealing with errors.
Exception handling is used to change the normal flow of the code execution if a
specified error (exceptional) condition occurs. This condition is called an exception.

This is what normally happens when an exception is triggered:


 The current code state is saved
 The code execution will switch to a predefined (custom) exception handler
function
 Depending on the situation, the handler may then resume the execution
from the saved code state, terminate the script execution or continue the script
from a different location in the code
We will show different error handling methods:
 Basic use of Exceptions
 Creating a custom exception handler
 Multiple exceptions
 Re-throwing an exception
 Setting a top level exception handler

h.Session handling Handling in PHP :

FIG M2. 19Session handling

Handling in PHP :
g .Error and Exception handling in PHP:

FIG M2.20 ERROR IN PHP

h.Why use fliters in PHP ?


FIG M2.21 FILTERS IN PHP
i.Connecting to a database :

j.PHP with a ODBC :


he Microsoft Open Database Connectivity (ODBC) is a C application programming
language interface. So the applications can access data from different database
management systems. The designers of ODBC aimed to make it independent of
database systems and operating systems. In this article, we are using the Microsoft
Access database to establish a connection.
Requirements: If ODBC Drivers are installed or the old version is installed, then
update to the latest version or install the driver first
 Start XAMPP server by starting Apache
 Write PHP script for Access database connection.
 Run it in a local browser.
 The database is successfully connected.
REFERENCES:
I TOOK MY REFERNCES FROM “w3school website “ and
“Geeks for Greeks “ including image I uploaded and data that I
have entered.

You might also like