Apache MySQL Php - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Apache MySQL Php

Description:

Apache is the de-facto standard in web servers, it is FOSS ... link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' ... – PowerPoint PPT presentation

Number of Views:996
Avg rating:3.0/5.0
Slides: 51
Provided by: mud7
Category:

less

Transcript and Presenter's Notes

Title: Apache MySQL Php


1
Apache MySQL Php
  • Robert Mudge

Reference http//www.w3schools.com/php/
2
What is Apache?www.apache.org
  • Apache is the de-facto standard in web servers,
    it is FOSS
  • Apache powers over 70 of all web sites
  • Apache is secure, reliable and fast
  • Apache is easy to install and configure
  • Apache will run on Windows, Linux and UNIX

3
What is PHP?www.php.net
  • 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

4
What is MySQL?www.mysql.com
  • 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

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

6
Learning Pyramid
PHP
SQL
Program Design
Cascading Style Sheets
HTML/xHTML Scripting
Object Oriented Design
Programming C/Java
Internet / Web Server / Database Server
7
System Configuration
  • Apache Server Installation
  • Apache/conf/httpd.conf
  • Add module php
  • MySQL Server Installation
  • my.ini
  • passwords
  • PHP Installation
  • php.ini
  • add module for MySQL

8
Debugging in Php
  • Php.ini settings
  • Print statements
  • Debuggers
  • Dbg (http//dd.cron.ru/dbg/)
  • Gubed (http//sourceforge.net/projects/gubed/)
  • Summaryhttp//www-128.ibm.com/developerworks/libr
    ary/os-debug/

9
PHP Introduction
  • PHP File
  • HTML Header
  • PHP script delimiter
  • PHP Comments
  • PHP Variables
  • PHP Language
  • PHP Functions/Manual

10
What is a PHP File?
  • PHP files may contain text, HTML tags and scripts
  • PHP files are returned to the browser as plain
    HTML 
  • PHP files have a file extension of ".php",
    ".php3", or ".phtml"

11
HTML File Format
4.01//EN" "http//www.w3.org/TR/html4/strict.dtd"
content"text/html charsetiso-8859-1" Un
titled Document html
12
xHTML File Format
Add Doc Type
Transitional//EN" "http//www.w3.org/TR/xhtml1/DTD
/xhtml1-transitional.dtd"
type"image/x-icon" / Type" content"text/html charsetISO-8859-1"
/mysql, php, apache /content"web building course" /http-equiv"pragma" content"no-cache" / http-equiv"cache-control" content"no-cache" /
hrefmystyle.css" / Page
Title
l
Well FormedAll Tags open and close
or
13
PHP Script Delimiters


14
PHP Comments
/ This is a comment block / ?

15
PHP Variables
  • Variable Naming Rules
  • A variable name must start with a letter or an
    underscore "_"
  • A variable name can only contain alpha-numeric
    characters and
  • underscores (a-Z, 0-9, and _ )
  • A variable name should not contain spaces. If a
    variable name
  • should be more than one word, it should be
    separated with
  • underscore (my_string), or with capitalization
    (myString)

16
PHP Variables Concatenation
txt2"1234" echo txt1 . " " . txt2 ?

17
Arithmetic Operators
18
Assignment Comparison
19
Logical Operators
20
If elseif - else
21
switch-case-default
22
PHP Arrays
  • When working with PHP, sooner or later, you might
    want to create many similar variables. Instead of
    having many similar variables, you can store the
    data as elements in an array.
  • Each element in the array has its own ID so that
    it can be easily accessed.
  • There are three different kind of arrays
  • Numeric array - An array with a numeric ID key
  • Associative array - An array where each ID key is
    associated with a value
  • Multidimensional array - An array containing one
    or more arrays

23
Numeric Arrays
  • A numeric array stores each element with a
    numeric ID key.
  • There are different ways to create a numeric
    array.

24
Numeric Array - Examples
Output Quagmire and Joe are Peter's neighbors
25
Associative Arrays
  • An associative array, each ID key is associated
    with a value.
  • When storing data about specific named values, a
    numerical array is not always the best way to do
    it.
  • With associative arrays we can use the values as
    keys and assign values to them.

26
Associative Array - Example
  • Example 1
  • In this example we use an array to assign ages
    to the different persons

27
Associative Array - Examples
Output Peter is 32 years old.
28
Multi-dimensional Arrays
  • In a multidimensional array, each element in the
    main array can also be an array.
  • Each element in the sub-array can be an array,
    and so on.

29
Multi-dim Array Example
30
Repetition and Looping
  • Very often when you write code, you want the same
    block of code to run a number of times. You can
    use looping statements in your code to perform
    this.
  • 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

31
while loop
Zero to n loops
32
do while Loop
At least once n loops
33
for loop - repetition
  • The for statement is used when you know how many
    times you want to execute a statement or a list
    of statements.
  • Note The for statement has three parameters. The
    first parameter initializes variables, the second
    parameter holds the condition, and the third
    parameter contains the increments required to
    implement the loop. If more than one variable is
    included in the initialization or the increment
    parameter, they should be separated by commas.
    The condition must evaluate to true or false.

34
for loop - example
35
foreach loop
  • The foreach statement is used to loop through
    arrays.
  • For every loop, the value of the current array
    element is assigned to value (and the array
    pointer is moved by one) - so on the next loop,
    you'll be looking at the next element.

36
foreach - Example
37
Php Functions
  • A function is a block of code that can be
    executed whenever we need it.
  • Creating PHP functions
  • All functions start with the word "function()"
  • Name the function - It should be possible to
    understand what the function does by its name.
    The name can start with a letter or underscore
    (not a number)
  • Add a ""  - The function code starts after the
    opening curly brace
  • Insert the function code
  • Add a ""  - The function is finished by a
    closing curly brace

38
Function Example
echo John Smith" writeMyName() ?

39
Function Parameters
writeName(first, second) echo first .
second .
writeName(John,
Smith) ?
40
Function Returns
second) name first . second .

return name getName(John,
Smith) ?
41
Forms and User Input
  • The PHP _GET and _POST variables are used to
    retrieve information from forms, like user input.
  • The most important thing to notice when dealing
    with HTML forms and PHP is that any form element
    in an HTML page will automatically be available
    to your PHP scripts.
  • print_r(_POST)
  • echo _SERVER'PHP_SELF'

42
Forms Example
input.php
welcome.php
43
Form Validation
  • User input should be validated on the browser
    whenever possible (by client scripts
    (JavaScript)). Browser validation is faster and
    you reduce the server load.
  • You should consider using server validation if
    the user input will be inserted into a database.
  • A good way to validate a form on the server is to
    post the form to itself, instead of jumping to a
    different page. The user will then get the error
    messages on the same page as the form. This makes
    it easier to discover the error.

44
Php _GET
  • The _GET variable is used to collect values from
    a form with method"get".
  • The _GET variable is an array of variable names
    and values sent by the HTTP GET method.
  • The _GET variable is used to collect values from
    a form with method"get". Information sent from a
    form with the GET method is visible to everyone
    (it will be displayed in the browser's address
    bar) and it has limits on the amount of
    information to send (max. 100 characters).

45
Php _GET Example
input.php
welcome.php
http//localhost/welcome.php?namePeterage37
46
Php _GET Considerations
  • When using the _GET variable all variable names
    and values are displayed in the URL.
  • This method should not be used when sending
    passwords or other sensitive information.
  • The variables are displayed in the URL, it is
    possible to bookmark the page. This can be useful
    in some cases.
  • The HTTP GET method is not suitable on large
    variable values the value cannot exceed 100
    characters.

47
Php _REQUEST
  • The PHP _REQUEST variable contains the contents
    of both _GET, _POST, and _COOKIE.
  • The PHP _REQUEST variable can be used to get the
    result from form data sent with both the GET and
    POST methods.

48
Php _POST
  • _POST variable is used to collect values from a
    form with method"post".
  • The _POST variable is an array of variable names
    and values sent by the HTTP POST method.
  • The _POST variable is used to collect values
    from a form with method"post". Information sent
    from a form with the POST method is invisible to
    others and has no limits on the amount of
    information to send.

49
Php _POST Example
input.php
welcome.php
50
Homework 2
  • Create a Login Web Page
  • User enters username and password
  • Upon successful input and comparison to a hard
    coded password, present a welcome page showing
    the username and password
  • Turn in your source code and screen captures from
    the operation through a web server.
Write a Comment
User Comments (0)
About PowerShow.com