M D ANANDA RAJ,
Assistant Professor,
Department of computer science
Loyola College, chennai-600 034
profmdloyola@gmail.com
8/3/2017 1
Introduction to
Web Programming using
PHPand MYSQL
Contents
• Introduction
• History
• Important concepts
• Php
• Mysql
• Database concepts
8/3/2017 2
What is Scripting language?
• Scripting language is the one which is used to
develop contents in the web
• Write the code by using predefined tags
<html> contents </html>
• Example :
• HTML, JAVASCRIPT, VBSCRIPT, CSS , XML
8/3/2017 3
What is Client & Server
Client:
client is the system which is looking for
some service
Eg: the system end user using in the lab
Server:
server is the system which is providing
service for the clients (end user)
Eg: server in the computer lab
8/3/2017 4
Client side…
• Client side scripting language executed from
the client machine(System)
example : HTML , CSS, JAVASCRIPT, VBSCRIPT
- Not secured
- any user can view the original by seeing the
view source option in the browser
- any user can view the source code
and modify
8/3/2017 5
Server side …
• Server side scripting language executed from the
server machine(System)
example : ASP , PHP , JSP
- Very much secured
- User cannot view the original source code by
seeing the view source option in the browser it
will show only the html code
- user cannot modify the source code
8/3/2017 6
web contents
• Web can be classified in to two types
1.static page
-contents will not change remain as it is
-user input interaction not possible
2. Dynamic page :
- Contents can be updated very easily
- user input and interaction is possible
8/3/2017 7
What is Open source?
• In software development Open source is the
concept or philosophy that promotes free
distribution of software product without any
license fees.
• Example: open source
• Operating System: Linux
• Script language : PHP,PERL, PYTHON
• Browser : Mozilla Firefox
• Photo Editor : GIMP
• Office : Open Office
8/3/2017 8
Open source development model
View/Modify the source code of an application or software.
he source code of an application or software.
Open source software is released to the development community
and undergoes a secondary phase of evolution, but closed source
software is developed in isolation with a small team of developers.
Developer support and large community to help.
Open Source is more secure and bugs and vulnerabilities are fixed
often.
 source software is released to the development community and
undergoes a secondary phase of evolution, but closed source
software is developed in isolation with a small team of developers.
Developer support and large community to help.
Open Source is more secure and bugs and vulnerabilities are fixed
often.
8/3/2017 9
Advantages…
• Free source code
• No need pay license fees
• No need to depend on vendors
• Easy to fix the error with online support
• Support from forum all around the world
• Updated software version
• Quality and customizable software
• Cost cheaper than licensed software
8/3/2017 10
Disadvantages…
• Users need to update very frequently
• Incompatibility issue with software and
hardware
• Bad codes
• Software quality assurance process is not
transparent
• No financial benefit for the developers
8/3/2017 11
What is wamp?
• WAMP is a web server used to execute php
and mysql in client machine
• A- APACHE
• M- MySQL
• P- PHP
• W- WINDOWS
It is “ APACHE MYSQL PHP FOR WINDOWS
LAMP : APACHE MYSQL PHP FOR LINUX
8/3/2017 12
WAMP ARCHITECTURE…
8/3/2017 13
PHP-Introduction
• PHP == ‘Hypertext Preprocessor’
• Open-source, server-side scripting language
• Used to generate dynamic web-pages
• PHP scripts reside between reserved PHP
tags
– This allows the programmer to embed PHP
scripts within HTML page
– Free to download and use
8/3/2017 14
Overview of PHP…
• Easy learning
• Syntax Perl- and C-like syntax. Relatively easy
to learn.
• Large function library
• Embedded directly into HTML
• Interpreted, no need to compile
• Supports many databases like oracle, MySQL
etc
8/3/2017 15
Php…
• Interpreted language, scripts are parsed at
run-time rather than compiled
• Executed on the server-side
• Source-code not visible by client
– ‘View Source’ in browsers does not display the PHP code
• Various built-in functions allow for fast
development
• Compatible with many popular databases
8/3/2017 16
History of php…
In 1994 developed by Rasmus Lerdorf developed
he called the Personal Home Page or PHP
PHP 2 released 1997 (PHP now stands for
Hypertext Processor)
PHP3 released in 1998 (2 versions)
PHP4 released in 2000 (6 versions).
PHP5.0.0 released July 13, 2004 (1000s of
libraries and functions
PHP5.0.5 released Sept. 6, 2005 for maintenance
and bug fixes (21 versions)
PHP 6.0 is the latest version
8/3/2017 17
Features of php…
• Simplicity
• Portability
• Speed
• Open source
• Extensible
• Database support
8/3/2017 18
Hello.php
• Open the note pad
<html>
<?php
Echo “hello good morning”;
?>
</html>
Save this code as hello.php under
c:wampwwwanandhello.php
8/3/2017 19
Data types supported by PHP:
• Integers 0,1,2,3etc
• Float/ Double – real numbers 0.1, 0.2, 0.3, etc
• String – ‘A’, “Loyola College” etc
• Boolean – True or False
• Array – set of values – {0,1,2,3}or
{0.1,0.2,0.3}or {‘A’, ‘B’, ‘C’} or {“kumar”,
Santhosh”, “Karthick”} etc
8/3/2017 20
Variable declaration
Variables are used for storing values, such as numbers, strings or
function results, so that they can be used many times in a script .All
variables in PHP start with a $ sign symbol.
Syntax:
$var_name = value;
<?php
$txt = "Hello World!";
$number = 16;
?>
Note : PHP a variable does not need to be declared before being
set.PHP automatically converts the variable to the correct data
type, depending on how they are set.
8/3/2017 21
PHP Variable….
• PHP variables must begin with a “$” sign
• Case-sensitive ($Name != $NAME != $NaMe)
• Global and locally-scoped variables
– Global variables can be used anywhere
– Local variables restricted to a function or class
• Certain variable names reserved by PHP
– Form variables ($_POST, $_GET)
– Server variables ($_SERVER)
– Etc.
8/3/2017 22
constants
• PHP constants: Constants are like variables
except that once they are defined they cannot
be changed or undefined. The value cannot be
changed during the script.
• Eg:
<?php
define("MSG", “good morning");
echo MSG;
?>
8/3/2017 23
Looping
• Most of the time when we write code, we want the same
block of code to run a number of times for this purpose we
can use looping statements code to perform this task.
• PHP supports the following:
• while - loops through a block of code if and as long as a
specified condition is true
• do...while - loops through a block of code once, and then
repeats the loop as long as a special condition is true
• for - loops through a block of code a specified number of
times
• foreach- loops through a block of code for each element in
an array
8/3/2017 24
Example for each
• Example:
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
?>
8/3/2017 25
cookies
• A cookie is often used to identify a user. A
cookie is a small file that the server embeds
on the user's computer.
• Each time the same computer requests a
page with a browser, it will send the cookie
too.
• With PHP, you can both create and retrieve
cookie values.
8/3/2017 26
What is a PHP Session?
• 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
• Session variables solve this problem by storing user
information to be used across multiple pages (e.g.
username, password etc). By default, session variables
last until the user closes the browser.
• Session variables hold information about one single
user, and are available to all pages in one application.
8/3/2017 27
MySQL…
MySQL, the most popular Open Source SQL database
management system
It is developed and supported by MySQL AB. MySQL AB is a
commercial company, founded in 1995 by the MySQL
developers.
The MySQL® software delivers a very fast, multi-threaded,
multi-user, and robust SQL (Structured Query Language)
database server.
The MySQL software is Dual Licensed. Users can choose to
use the MySQL software as an Open Source product and
also as commericial licence
8/3/2017 28
MySQL…
• MySQL is a very popular, open source
database.
• Officially pronounced “my Ess Que Ell” (not
my sequel).
• Handles very large databases; very fast
performance.
8/3/2017 29
MySQL storage engines…
• MyISAM –default engine
• InnoDB – features like foreign key,locking
• MERGE – integration of table
• MEMORY (HEAP) – suit for short time storage
• BDB (BerkeleyDB)- hash based storage
• EXAMPLE – used for programmers
• ARCHIVE –to store large amount of data
• CSV – to store data in text files
• BLACKHOLE –only for testing purpose
• ISAM – to store non transactional tables
8/3/2017 30
THANK YOU8/3/2017 31