SlideShare a Scribd company logo
By Sanketkumar Biswas
          1
Client Server Arch.




         2
Server Side
             Scripting


Generates dynamic web pages.

Practically invisible to end - user.




                         3
Web Application



An application that runs within a web browser.

And can be accessed over a network.




                       4
What is PHP ?


It is a server side scripting language used for
web development.

Created by Rasmus Lerdorf in 1995




                        5
Why PHP ?

Open Source

Very good set of built in functions

Very good database support

Great support community

Many frameworks


                        6
Getting started with PHP


<?php

echo "Hello World";

?>




                      7
Including files

include('/filepath/filename/')

include_once('/filepath/filename/')

require('/filepath/filename/')

require_once('/filepath/filename/')



                         8
PHP Syntax
PHP is programmer centric.

HTML and PHP are not same.

PHP is white space insensitive.

PHP is sometimes case sensitive.

Termination by semicolon (;)

Braces define blocks.
                        9
Programmer Centric



Focuses on convenience for programmer.

Does not focus much on correctness.




                     10
HTML Vs. PHP



HTML is client side.

PHP is server side.




                       11
White space Insensitive
<?php

$val = 2 + 2; //single spaces

$val =       2 +   2; //spaces and tabs

$val     =

2

+    2; //multiple lines

?>
                           12
Case Sensitive

<?php

$val = 20;

echo "variable value is $val";

echo "variable value is $VaL";

?>


                          13
Case Sensitive
<?php

HELLO();

function hello() {

EcHo "Hello!!";

}

?>
                     14
Termination


<?php

echo "Hello World";

?>




                      15
Braces define block
<?php

if (1 == 1)

    echo "Hello World";

if (1 == 1) {

    echo "Hello ";

    echo "World";

}

?>                        16
Commenting
<?php

// this is a single line comment.

# this is also a single line comment.

/* this is a

   multi line

   comment. */

?>
                          17
Variables

Variables are denoted with a leading ($) sign.

Value of variable is the most recent assignment.

Variable is assigned using (=) operator, to its left
is the variable and to right is the expression to
be evaluated.



                        18
Variables can, but do not need to be declared
before assignment.

Variables have no type other than the type of its
current value.

Variables should always start with an alphabet.

Numerical values for a variable can be INT,
HEX, OCT, FLOAT and e.



                       19
In variables for text we can use () as escape
character.

Boolean values is not case sensitive, TRUE,
TRuE, true, trUE, etc.

Prefix for HEX is "0x" and for OCT is "0".

Range of INT varies with respect to processor
bits, i.e. different for 32 and 64 bit processor.



                        20
$x = 'Hello';

 $x = "Hello";

 $x = <<<var

Hello

var;

 Single quotes display as it is, whereas double
 quotes and heredoc do interpretation.


                        21
Creating a variable

$x = 3;

 Changing value

$x = $x + 5;

 Changing value as well as type

$x = $x + 0.5;



                       22
Global Variables:

$x = "HELLO";

function test() {

     global $x;

     return $x;

}

echo test();

    Super Global Variables: $_POST, $_GET, etc.
                          23
Outputting


echo "Hello World n Welcome to PHP";

echo "Hello World <br> Welcome to PHP";

echo "$var1 n $var2";




                         24
Arrays
Creating arrays

$array = array(1, -2, 'cat', TRUE);

$array[] = 2.6;

$array[5] = 012;

$array[] = 0xA;

$array[7] = 5e2;
                          25
Creating arrays with index

$array = array(

0 => 1,

1 => -2,

2 => 'cat',

3 => TRUE

);

                         26
Creating arrays with string index

$array = array(

'INT' => 1,

'NINT' => -2,

'STRING' => 'cat',

'BOOLEAN' => TRUE

);

                         27
Creating multi dimensionsl arrays

$array = array(

     'INT' => array(

         'POS' => 1,

         'NEG' => -2

     )

);

                        28
Deleting arrays

unset($array[2]);



Unset is not the same as,

$array[2] = "";




                        29
Iterating arrays

$array = array(

'INT' => 1, 'NINT' => -2, 'STRING' => 'cat'

);

foreach($array as $element) {

     echo $element."<br>";

}


                             30
Operators
Arithmetic > Comparison > Logical

Arithmetic: +, -, *, /, %

Comparison: ==, ===, !=, !==, ......

Logical: and, or, !, .......

break: used to stop loops.

continue: used to stop iteration.
                            31
Arithmetic Operators




                       32
Comparison Operators




                       33
Logical Operators




                    34
Constants



Defining a constant

define("CONSTANT_NAME","VALUE");




                      35
Type Casting


$variable = (TYPE) VALUE;

$x = 5.5;

$y = (INT) $x; // $y = 5




                           36
Functions
Declaration:

function NAME(ARG1, ARG2=DEFAULT);

Eg:

$x = "Hello";

function app($x,$s="World") {

    return $x . $s;

}

$a = app($x);           // HelloWorld

$b = app($y,"India");    // HelloIndia
                                         37
Some Important
          Functions

strlen(): gives length of string.

strcmp(x,y): case sensitive string compare.

strcasecmp(x,y): case in sensitive string
compare.

strncmp(x,y,n): checks first n characters.


                         38
strtoupper(x): converts to uppercase.

strtolower(x): converts to lowercase.

trim(x): removes white space.

substr(x,m,n): creates substring of x from m to n
characters.

ord(x): gives int value for character.



                        39
count(x): gives no. Of elements in array.

isset(x): checks if has value.

sort(x): sorts array wrt values.

ksort(x): sorts array wrt keys.

array_merge(x,y): merge arrays to a new one.




                        40
array_slice(x,m,n): creates a sub array of x from
m key to the next n keys.




                       41
Branching
    if... else...

if ($a > $b) {

    $c = $a - $b;

    echo $c;

} else {

    $c = $b - $a;

    echo $c;

}                       42
switch

switch($a) {

    case 1: echo "one"; break;

    case 2: echo "two"; break;

    case 3: echo "three"; break;

    default: echo "no number"; break;

}

                           43
Looping
    while

$count = 1;

while ($count <= 10) {

     echo "Count is $count n";

     $count++;

}
                           44
do - while

$count = 45;

do {

  echo "Count is $count n";

  $count++;

} while ($count <= 10);



                          45
for

$limit = 5;

for($count=0; $count<$limit; $count++)

{

    echo "Count is $count n";

}



                            46
PHP and Forms

HTTP is a stateless protocol

Data is sent using

    GET

    POST



                      47
To collect data for PHP processing we use super
global variables.

    $_GET

    $_POST




                     48
PHP and MySQL
Initialise a database connection

mysql_connect('host','username','pass');

mysql_select_db('dbname');



Firing a query

mysql_query('Query');
                        49
<?php

mysql_connect('localhost','root','');

mysql_select_db('demo');

$res = mysql_query('SELECT * FROM table');

while ($row = mysql_fetch_assoc($res))

{ echo $row['name']; }

?>

                           50
Session


PHP Session variable is super global.

It has values of a single user across many pages
in an application.

It is located server side.



                        51
Starting Session

 session_start();

Session Variable

 $_SESSION['username']

Destroying Session

 session_destroy();



                      52
Cookie


Cookie is also super global variable.

It is used to store information about user and its
visit on user's computer.

It is located client side.



                             53
Setting cookie

setcookie('name','rohit',time()+(3600));

 Cookie variable

 $_COOKIE['name']




                          54
Thank You

Follow me on:

Facebook: http://fb.com/sanketkumarbiswas/

Twitter: @sankeybiswas

LinkedIn: http://linkedin.com/in/sanketkumarbiswas/

Web: http://www.sankeybiswas.com/

Cell: +91 9820 477 377


                                 55

More Related Content

What's hot (20)

PDF
What's New in Perl? v5.10 - v5.16
Ricardo Signes
 
PDF
Teaching Your Machine To Find Fraudsters
Ian Barber
 
PPTX
Electrify your code with PHP Generators
Mark Baker
 
PDF
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
PPT
Functional Pe(a)rls version 2
osfameron
 
PDF
Learning Perl 6 (NPW 2007)
brian d foy
 
PDF
Learning Perl 6
brian d foy
 
KEY
Php 101: PDO
Jeremy Kendall
 
PDF
Descobrindo a linguagem Perl
garux
 
PDF
Command Bus To Awesome Town
Ross Tuck
 
DOCX
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
PDF
Doctrine fixtures
Bill Chang
 
PDF
Wx::Perl::Smart
lichtkind
 
PDF
PHP Data Objects
Wez Furlong
 
PDF
Models and Service Layers, Hemoglobin and Hobgoblins
Ross Tuck
 
PDF
Object Calisthenics Adapted for PHP
Chad Gray
 
PDF
The Perl6 Type System
abrummett
 
PPT
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
PDF
Dependency injection - phpday 2010
Fabien Potencier
 
What's New in Perl? v5.10 - v5.16
Ricardo Signes
 
Teaching Your Machine To Find Fraudsters
Ian Barber
 
Electrify your code with PHP Generators
Mark Baker
 
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
Functional Pe(a)rls version 2
osfameron
 
Learning Perl 6 (NPW 2007)
brian d foy
 
Learning Perl 6
brian d foy
 
Php 101: PDO
Jeremy Kendall
 
Descobrindo a linguagem Perl
garux
 
Command Bus To Awesome Town
Ross Tuck
 
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
Doctrine fixtures
Bill Chang
 
Wx::Perl::Smart
lichtkind
 
PHP Data Objects
Wez Furlong
 
Models and Service Layers, Hemoglobin and Hobgoblins
Ross Tuck
 
Object Calisthenics Adapted for PHP
Chad Gray
 
The Perl6 Type System
abrummett
 
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Dependency injection - phpday 2010
Fabien Potencier
 

Similar to PHP and MySQL (20)

PDF
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
PDF
Php tips-and-tricks4128
PrinceGuru MS
 
PPT
Web Technology_10.ppt
Aftabali702240
 
PPTX
Php & my sql
Norhisyam Dasuki
 
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
PDF
PHP tips and tricks
Damien Seguy
 
PDF
Web app development_php_04
Hassen Poreya
 
PDF
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
PPT
Php basic for vit university
Mandakini Kumari
 
PPT
Introduction to Perl
NBACriteria2SICET
 
PDF
Zend Certification PHP 5 Sample Questions
Jagat Kothari
 
PDF
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
PPT
Php Lecture Notes
Santhiya Grace
 
PPT
Introduction to PHP
prabhatjon
 
PPTX
php programming.pptx
rani marri
 
PDF
PHP Conference Asia 2016
Britta Alex
 
PPT
PHP-01-Overview.pptfreeforeveryonecomenow
oliverrobertjames
 
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
Php tips-and-tricks4128
PrinceGuru MS
 
Web Technology_10.ppt
Aftabali702240
 
Php & my sql
Norhisyam Dasuki
 
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
PHP tips and tricks
Damien Seguy
 
Web app development_php_04
Hassen Poreya
 
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
PHP Functions & Arrays
Henry Osborne
 
Php basic for vit university
Mandakini Kumari
 
Introduction to Perl
NBACriteria2SICET
 
Zend Certification PHP 5 Sample Questions
Jagat Kothari
 
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Php Lecture Notes
Santhiya Grace
 
Introduction to PHP
prabhatjon
 
php programming.pptx
rani marri
 
PHP Conference Asia 2016
Britta Alex
 
PHP-01-Overview.pptfreeforeveryonecomenow
oliverrobertjames
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Ad

PHP and MySQL