SlideShare ist ein Scribd-Unternehmen logo
1 von 55
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

Weitere ähnliche Inhalte

Was ist angesagt?

PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applications
Sunil Kumar Gunasekaran
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
Bill Chang
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
Fabien Potencier
 

Was ist angesagt? (20)

What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applications
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 

Ähnlich wie PHP and MySQL

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
Hassen Poreya
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

Ähnlich wie PHP and MySQL (20)

Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

PHP and MySQL