SlideShare ist ein Scribd-Unternehmen logo
1 von 29
PHP Basic
 Mandakini Kumari
 22 July 2012
   nd
 http://www.slideshare.net/mandakinikumari
                         Mandakini
                     Ayushi Infotech
Overview
A Brief History
What is PHP
Why PHP
PHP Stack
PHP Syntax
Variables
PHP String
PHP Operators
Overview
PHP Arrays
PHP If...Else
PHP Switch
PHP While
For Loop
Foreach
Function
Form,Get,Post
Overview
Object
Database Connection
Database Query
Sessions & Cookies
A brief history
• Created by Rasmus Lerdorf in 1995
• PHP: Hypertext Preprocessor
• PHP interpreters available on 32-bit
  and 64-bit operating systems
What is PHP
• Similar Syntax as C or Perl
• PHP stands for PHP: Hypertext Preprocessor
• PHP files have a file extension of ".php", ".php3",
  or ".phtml"
• PHP is a server-side scripting language, like ASP
• PHP scripts are executed on the server
• PHP supports many databases (MySQL, Informix,
  Oracle, Sybase, Solid, PostgreSQL, Generic
  ODBC, etc.)
• PHP is an open source software
Why PHP
•   PHP runs on different platforms (Windows,
 Linux, Unix, etc.)
• PHP is compatible with almost all servers used
 today (Apache, IIS, etc.)
• PHP is FREE to download from the official PHP
 resource: www.php.net
• PHP is easy to learn and runs efficiently on the
 server side
The Stack
• Apache (lighttpd, IIS)
• MySQL (PostgresSQL, SQL Server,
  Oracle)
• PHP
• PHPMyAdmin for adminisering your
  SQL Database
• Linux (BSD, Mac OS, Windows,
  Solaris)
The Stack
Syntax
<?php
echo "Hello World";
?>
PHP Variables
<?php
$txt="Hello World!";
$x=16;
?>
PHP Variable Types

    Local

    Global

    Static

    Parameter
PHP Global Variable
$a = 5; $b = 10;
function myTest()
{
global $a, $b;
$b = $a + $b;
}
myTest();
echo $b;
PHP Local Variable
$a = 5; // global scope
function myTest()
{
echo $a; // local scope
}
myTest();
PHP Static & Parameters
static $rememberMe;
function
  myTest($para1,$para2)
{
}
Operators
x + y Addition       Sum of x and y        2+2 4
x-y      Subtraction Difference of x and y       5-2     3
x * y Multiplication        Product of x and y 5 * 2 10
x/y      Division    Quotient of x and y         15 / 5 3
x % y Modulus        Remainder of x divided by y         5%2
- x Negation Opposite of x         -2
a.b      Concatenation      Concatenate two strings "Hi" . "Ha"   HiHa
x && y         And   True if both x and y are true
x || y Or      True if either or both x and y are true
PHP Array
$cars=array("Saab","BMW","Toyota");
$ages = array("ass1"=>32, "associative2"=>30);
$cars[0]="Saab";
$cars[2]="BMW";
$cars[3]="Toyota";
echo $cars[0] . " and " . $cars[1];
If else Statement
if (condition)
 {
 code to be executed if condition is true;
 }
else
 {
 code to be executed if condition is false;
 }
Switch Statement
$x=1;
switch ($x)
{
case 1:
    echo "Test Number 1";
    break;
case 2:
    echo "Test Number 2";
    break;
default:
    echo "No test number between 1 and 2"; }
While Statement
$i=1;
while($i<=5)
 {
 echo "This number is " . $i . "<br />";
 $i++;
 }
For Loop
for ($i=1; $i<=5; $i++)
 {
 echo "The number is " . $i .
 "<br />";
 }
Foreach Loop
$x=array("one","two","three");
foreach ($x as $value)
 {
 echo $value . "<br />";
 }
Function
<?php
 function add($x,$y)
 {
 $total=$x+$y;
 return $total;
 }
 echo "1 + 16 = " . add(1,16);
 ?>
HTML Form
<form action="welcome.php"
 method="post">
 Name: <input type="text"
 name="fname" />
 Age: <input type="text" name="age" />
 <input type="submit" />
</form>
GET & POST
 Welcome <?php echo $_POST["fname"]; ?>
 You are <?php echo $_POST["age"]; ?> years old.
OR
http://example.com/test.php?fname=Peter&age=37
 Welcome <?php echo $_GET["fname"]; ?>.<br />
 You are <?php echo $_GET["age"]; ?> years old!
Mysql Connection
$con =
  mysql_connect("localhost","peter","abc123");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  mysql_select_db("my_db", $con);
  mysql_close($con);
Mysql Query

 $sql="INSERT INTO Persons (FirstName, Age)
  VALUES
  ('$_POST[fname], '$_POST[age]')";
mysql_query($sql);


Select * FROM Persons
Update/Delete
Session & Cookie
session_start();
  if(isset($_SESSION['views']))
    unset($_SESSION['views]);

session_destroy();
setcookie(name,value,expire,domain,path,domain,secure,http
  only);
setcookie("TestCookie", $value, time()
  +3600, "/~rasmus/", "example.com", 1);
Thank you

Contact me @

http://www.linkedin.com/pub/mandakini-kumari/18/93/935
https://www.facebook.com/mandakini.kumari

Weitere ähnliche Inhalte

Was ist angesagt?

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5
Michael Girouard
 

Was ist angesagt? (20)

Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshops
 
PHP Function
PHP Function PHP Function
PHP Function
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Fluentd unified logging layer
Fluentd   unified logging layerFluentd   unified logging layer
Fluentd unified logging layer
 
When dynamic becomes static : the next step in web caching techniques
When dynamic becomes static : the next step in web caching techniquesWhen dynamic becomes static : the next step in web caching techniques
When dynamic becomes static : the next step in web caching techniques
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!
 
MySQLi
MySQLiMySQLi
MySQLi
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
MongoDB & PHP
MongoDB & PHPMongoDB & PHP
MongoDB & PHP
 
Website Performance Basics
Website Performance BasicsWebsite Performance Basics
Website Performance Basics
 
Develop webservice in PHP
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHP
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 

Andere mochten auch (8)

Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
PHP basic
PHP basicPHP basic
PHP basic
 
Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)Html5 drupal7 with mandakini kumari(1)
Html5 drupal7 with mandakini kumari(1)
 
Drupal7 an introduction by ayushiinfotech
Drupal7 an introduction by ayushiinfotechDrupal7 an introduction by ayushiinfotech
Drupal7 an introduction by ayushiinfotech
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Seminar: PHP Developer for Dummies
Seminar: PHP Developer for DummiesSeminar: PHP Developer for Dummies
Seminar: PHP Developer for Dummies
 
Best topics for seminar
Best topics for seminarBest topics for seminar
Best topics for seminar
 

Ähnlich wie Php basic for vit university

HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
souridatta
 

Ähnlich wie Php basic for vit university (20)

FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
Php101
Php101Php101
Php101
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Intro to php
Intro to phpIntro to php
Intro to php
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Unit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptxUnit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptx
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Php
PhpPhp
Php
 

Mehr von Mandakini Kumari

Mehr von Mandakini Kumari (8)

Emerging Trends In Cloud Computing.pptx
Emerging Trends In Cloud Computing.pptxEmerging Trends In Cloud Computing.pptx
Emerging Trends In Cloud Computing.pptx
 
Building an Edge Computing Strategy - Distributed infrastructure.pptx
Building an Edge Computing Strategy - Distributed infrastructure.pptxBuilding an Edge Computing Strategy - Distributed infrastructure.pptx
Building an Edge Computing Strategy - Distributed infrastructure.pptx
 
Emerging Trends in Cloud Computing.pptx
Emerging Trends in Cloud Computing.pptxEmerging Trends in Cloud Computing.pptx
Emerging Trends in Cloud Computing.pptx
 
Women in IT & Inspirational Individual of the Year.pptx
Women in IT & Inspirational Individual of the Year.pptxWomen in IT & Inspirational Individual of the Year.pptx
Women in IT & Inspirational Individual of the Year.pptx
 
Big data with hadoop Setup on Ubuntu 12.04
Big data with hadoop Setup on Ubuntu 12.04Big data with hadoop Setup on Ubuntu 12.04
Big data with hadoop Setup on Ubuntu 12.04
 
Web services soap and rest by mandakini for TechGig
Web services soap and rest by mandakini for TechGigWeb services soap and rest by mandakini for TechGig
Web services soap and rest by mandakini for TechGig
 
Introduction of drupal7 by ayushi infotech
Introduction of drupal7 by ayushi infotechIntroduction of drupal7 by ayushi infotech
Introduction of drupal7 by ayushi infotech
 
Drupal 7 theme by ayushi infotech
Drupal 7 theme by ayushi infotechDrupal 7 theme by ayushi infotech
Drupal 7 theme by ayushi infotech
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
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
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Kürzlich hochgeladen (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Php basic for vit university

  • 1. PHP Basic Mandakini Kumari 22 July 2012 nd http://www.slideshare.net/mandakinikumari Mandakini Ayushi Infotech
  • 2. Overview A Brief History What is PHP Why PHP PHP Stack PHP Syntax Variables PHP String PHP Operators
  • 3. Overview PHP Arrays PHP If...Else PHP Switch PHP While For Loop Foreach Function Form,Get,Post
  • 5. A brief history • Created by Rasmus Lerdorf in 1995 • PHP: Hypertext Preprocessor • PHP interpreters available on 32-bit and 64-bit operating systems
  • 6. What is PHP • Similar Syntax as C or Perl • PHP stands for PHP: Hypertext Preprocessor • PHP files have a file extension of ".php", ".php3", or ".phtml" • PHP is a server-side scripting language, like ASP • PHP scripts are executed on the server • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) • PHP is an open source software
  • 7. Why PHP • PHP runs on different platforms (Windows, Linux, Unix, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP is FREE to download from the official PHP resource: www.php.net • PHP is easy to learn and runs efficiently on the server side
  • 8. The Stack • Apache (lighttpd, IIS) • MySQL (PostgresSQL, SQL Server, Oracle) • PHP • PHPMyAdmin for adminisering your SQL Database • Linux (BSD, Mac OS, Windows, Solaris)
  • 12. PHP Variable Types  Local  Global  Static  Parameter
  • 13. PHP Global Variable $a = 5; $b = 10; function myTest() { global $a, $b; $b = $a + $b; } myTest(); echo $b;
  • 14. PHP Local Variable $a = 5; // global scope function myTest() { echo $a; // local scope } myTest();
  • 15. PHP Static & Parameters static $rememberMe; function myTest($para1,$para2) { }
  • 16. Operators x + y Addition Sum of x and y 2+2 4 x-y Subtraction Difference of x and y 5-2 3 x * y Multiplication Product of x and y 5 * 2 10 x/y Division Quotient of x and y 15 / 5 3 x % y Modulus Remainder of x divided by y 5%2 - x Negation Opposite of x -2 a.b Concatenation Concatenate two strings "Hi" . "Ha" HiHa x && y And True if both x and y are true x || y Or True if either or both x and y are true
  • 17. PHP Array $cars=array("Saab","BMW","Toyota"); $ages = array("ass1"=>32, "associative2"=>30); $cars[0]="Saab"; $cars[2]="BMW"; $cars[3]="Toyota"; echo $cars[0] . " and " . $cars[1];
  • 18. If else Statement if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
  • 19. Switch Statement $x=1; switch ($x) { case 1: echo "Test Number 1"; break; case 2: echo "Test Number 2"; break; default: echo "No test number between 1 and 2"; }
  • 20. While Statement $i=1; while($i<=5) { echo "This number is " . $i . "<br />"; $i++; }
  • 21. For Loop for ($i=1; $i<=5; $i++) { echo "The number is " . $i . "<br />"; }
  • 22. Foreach Loop $x=array("one","two","three"); foreach ($x as $value) { echo $value . "<br />"; }
  • 23. Function <?php function add($x,$y) { $total=$x+$y; return $total; } echo "1 + 16 = " . add(1,16); ?>
  • 24. HTML Form <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form>
  • 25. GET & POST Welcome <?php echo $_POST["fname"]; ?> You are <?php echo $_POST["age"]; ?> years old. OR http://example.com/test.php?fname=Peter&age=37 Welcome <?php echo $_GET["fname"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old!
  • 26. Mysql Connection $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_close($con);
  • 27. Mysql Query $sql="INSERT INTO Persons (FirstName, Age) VALUES ('$_POST[fname], '$_POST[age]')"; mysql_query($sql); Select * FROM Persons Update/Delete
  • 28. Session & Cookie session_start(); if(isset($_SESSION['views'])) unset($_SESSION['views]); session_destroy(); setcookie(name,value,expire,domain,path,domain,secure,http only); setcookie("TestCookie", $value, time() +3600, "/~rasmus/", "example.com", 1);
  • 29. Thank you Contact me @ http://www.linkedin.com/pub/mandakini-kumari/18/93/935 https://www.facebook.com/mandakini.kumari