PHP - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

PHP

Description:

PHP – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 25
Provided by: cherihiggi
Category:

less

Transcript and Presenter's Notes

Title: PHP


1
PHP
  • Source www.w3schools.com

2
What is PHP?
  • PHP stands for PHP Hypertext Preprocessor
  • 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 (OSS)
  • PHP is free to download and use

3
What is MySQL?
  • MySQL is a small database server
  • MySQL is ideal for small and medium applications
  • MySQL supports standard SQL
  • MySQL compiles on a number of platforms
  • MySQL is free to download and use

4
PHP MySQL
  • PHP combined with MySQL are cross-platform (means
    that you can develop in Windows and serve on a
    Unix platform)

5
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

6
What do you need to get started?
  • Download PHP
  • Download PHP for free here http//www.php.net/dow
    nloads.php
  • Download MySQL Database
  • Download MySQL for free here http//www.mysql.com
    /downloads/index.html
  • Download Apache Server
  • Download Apache for free here http//httpd.apache
    .org/download.cgi
  • Or use the uniform server (www.uniformserver.com)

7
Hello World Example
  • There are two basic statements to output text
    with PHP echo and print.
  • lthtmlgt
  • ltbodygt
  • lt?php echo "Hello World" ?gt
  • lt/bodygt
  • lt/htmlgt
  • lthtmlgt
  • ltbodygt
  • lt?php print "Hello World" ?gt
  • lt/bodygt
  • lt/htmlgt

8
Variables in PHP
  • All variables in PHP start with a sign symbol.
    Variables may contain strings, numbers, or
    arrays.
  • lthtmlgt
  • ltbodygt
  • lt?php
  • // the . (dot operator) is for concatenation
  • txt1"Hello World"
  • txt2"1234"
  • echo txt1 . " " . txt2
  • ?gt
  • lt/bodygt
  • lt/htmlgt

9
Conditional Statements
  • In PHP we have two conditional statements
  • if (...else) statement - use this statement if
    you want to execute a set of code when a
    condition is true (and another if the condition
    is not true)
  • switch statement - use this statement if you want
    to select one of many sets of lines to execute
  • if (condition)
  • code to be executed if condition is true
  • else
  • code to be executed if condition is false

10
Conditional IF-ELSE
  • lthtmlgt
  • ltbodygt
  • lt?php
  • ddate("D")
  • if (d"Fri")
  • echo "Have a nice weekend!"
  • else
  • echo "Have a nice day!"
  • ?gt
  • lt/bodygt
  • lt/htmlgt
  • Also see conditional month

11
Conditional Switch
  • lthtmlgt
  • ltbodygt
  • lt?php
  • switch (x)
  • case 1
  • echo "Number 1"
  • break
  • case 2
  • echo "Number 2"
  • break
  • case 3
  • echo "Number 3"
  • break
  • default
  • echo "No number between 1 and 3"
  • ?gt
  • lt/bodygt

12
Looping
  • In PHP we have the following looping statements
  • 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

13
While Statement
  • while (condition)
  • code to be executed
  • lthtmlgt
  • ltbodygt
  • lt?php
  • i1
  • while(ilt5)
  • echo "The number is " . i . "ltbr /gt"
  • i
  • ?gt
  • lt/bodygt
  • lt/htmlgt

14
Do While Statement
  • do
  • code to be executed
  • while (condition)
  • lthtmlgt
  • ltbodygt
  • lt?php
  • i0
  • do
  • echo "The number is " . i . "ltbr /gt"
  • i
  • while (ilt5)
  • ?gt
  • lt/bodygt
  • lt/htmlgt

15
For Statement
  • for (initialization condition increment)
  • code to be executed
  • lthtmlgt
  • ltbodygt
  • lt?php
  • for (i1 ilt5 i)
  • echo "Hello World!ltbr /gt"
  • ?gt
  • lt/bodygt
  • lt/htmlgt

16
foreach Statement
  • foreach (array as value)
  • code to be executed
  • lthtmlgt
  • ltbodygt
  • lt?php
  • arrarray("one", "two", "three")
  • foreach (arr as value)
  • echo "Value " . value . "ltbr /gt"
  • ?gt
  • lt/bodygt
  • lt/htmlgt

17
Functions
  • The real power of PHP comes from its functions.
  • In PHP - there are more than 700 functions
    available.
  • Reference Manual at http//www.php.net/quickref.ph
    p

18
PHP Forms
  • lthtmlgt
  • ltbodygt
  • ltform action"welcome.php" method"POST"gt
  • Enter your name ltinput type"text" name"name"
    /gt
  • Enter your age ltinput type"text" name"age" /gt
  • ltinput type"submit" /gt
  • lt/formgt
  • lt/bodygt
  • lt/htmlgt

19
welcome.php
  • lthtmlgt
  • ltbodygt
  • Welcome lt?php echo _POST"name" ?gt.ltbr /gt
  • You are lt?php echo _POST"age" ?gt years old!
  • lt/bodygt
  • lt/htmlgt

20
welcome2.php alternative syntax
  • lthtmlgt
  • ltbodygt
  • lt?php
  • print Welcome name. ltbrgt
  • print You are age years old!
  • ?gt
  • lt/bodygt
  • lt/htmlgt

21
Simple Database Example
  • Submitted to getStudents1.php
  • Submitted to insertStudents1.php

22
mySQL database - itk352 with table students
23
getStudents1.php
  • lthtmlgtltbodygt
  • lt?php
  • host 'localhost'
  • user 'cheri'
  • passwd 'fake'
  • database 'itk352'
  • connect mysql_connect(host, user, passwd)
  • table_name 'students'
  • print 'ltfont size"5" color"blue"gt'
  • print "table_name Datalt/fontgtltbrgt"
  • if(account 'Any')
  • query "Select from table_name"
  • else
  • query "Select from table_name where
    account 'account'"
  • print "The query is ltigt query lt/igtltbrgt"
  • mysql_select_db(database)
  • result_id mysql_query(query, connect)

24
insertStudents1.php
  • lt?php
  • host 'localhost'
  • user 'cheri'
  • passwd 'fake'
  • database 'itk352'
  • connect mysql_connect(host, user, passwd)
  • table_name 'students'
  • ...
  • query "Insert into table_name values
    ('firstName', 'lastName', 'account', 'ulid',
    'class', 'password')"
  • print "The query is ltigt query lt/igtltbrgtltbrgt"
  • result_id mysql_query(query, connect)
  • ?gt
  • lt/bodygt
  • lt/htmlgt
Write a Comment
User Comments (0)
About PowerShow.com