1 / 29

LAMP Architecture

LAMP Architecture. Typical PHP and MYSQL application development framework follows “LAMP “ Architecture “LAMP”(Linux , Apache , MySQL and PHP) platform wherein each component plays an important role. LINUX provides the base OS and Server Environment. LAMP Architecture.

Download Presentation

LAMP Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LAMP Architecture • Typical PHP and MYSQL application development framework follows “LAMP “ Architecture • “LAMP”(Linux , Apache , MySQL and PHP) platform wherein each component plays an important role. • LINUX provides the base OS and Server Environment

  2. LAMP Architecture • The Apache Web Server intercepts HTTP requests and either serves them directly or passes them onto the PHP interpreter for execution • The PHP interpreter parses and executes PHP code & returns the results to the webserver • MYSQL RDMS serves as the data storage engine , built connections from PHP Layer for inserting , modifying or retrieving data.

  3. Learning PHP Learning Basics

  4. Embedding PHP in HTML • There are three possibilities • <?php ….PHP code … ?> • <? …..PHP Code ….. ?> • <% …..PHP Code…. %> • <script language = “php”> ……PHP Code </ script >

  5. Sending output to Browser • Echo <?php echo “Hello From PHP “ ; ?> Echo is not a function but a language Construct which sends a String value to the Browser How PHP Works • ends with ; • Code blocks are enclosed in { } • Comments begin with // or # (Single line) and /* …. */ (For Multi Line)

  6. To run a Simple PHP File • Make sure that PHP and IIS is installed and properly running • Save Every PHP code with .php extension in directory c:/intepub/wwwroot/php/filename.php • To access the file type in the url bar of IE http://localhost/php/filename.php

  7. Language Basics • Variable Names • Begin with a $ sign • First Letter after the $ must be a letter or an underscore • Remaining letters may be numbers or underscores w/o a fixed limit • Case-sensitive • Longer than 30 characters impractical

  8. Data Types • PHP is loosely typed language don’t requires declaration of a variable type and automatically convert variable type depending upon the context in which they are used and operations performed on their values • Enables you to check the data type whenever you want to • Supports following data types

  9. Data Types • Boolean • Integer • Float • String • Array • Object • Resource • NULL

  10. Assigning & Using Variable Values • <?php $age = $dob +15; ?> • <?php $today = “Jan 05 2004”; echo “today is $today “ ; ?>

  11. Detecting the Data type • Use of gettype() function <?php $auth = true; $age = 27 ; $name = ‘Bobby’; $temp = 98.6; //returns String echo gettype($name) ; //returns String echo gettype($name) ; //returns Boolean echo gettype($auth) ; //returns integer echo gettype($age) ; //returns double echo gettype($temp) ; ?>

  12. Detecting the Data type • Specialized functions • is_bool • is_string • is_numeric • is_float • is_int • is_null • is_array • is_object

  13. NULL Values • A Null is typically seen when a variable is initialized but not assigned a value <?php //checks type of un initialized variable //returns NULL echo gettype($me); $me = “Mysterious”; //Check type again //returns STRING echo gettype($me); Unset($me); //returns NULL echo gettype($me); ?>

  14. Using Operators • <?php $num1 = 101; $num2 = 5; $sum = $num1 + $num2; $diff = $num1 - $num2; $product = $num1 * $num2; $quotient = $num1 / num2 ; $remainder = $num1 % $num2 ; ?>

  15. Using Operators

  16. The === Operator <?php //define two variables $str = ’14’; $int = 14; //returns true b/c contains the same value $result = ($str == $int ); //returns false b/c variables are not of the same types $result = ($str === $int ); ?>

  17. if() Statement <?php if (conditional test) { do this; } else { do this; } ?>

  18. If elseif PHP also provides if-elseif-else() construct <?php if (conditional test) { do this; } elseif (conditional test #1) { do this; } ……….. elseif (conditional test #N) { do this; } else { do this ; } ?>

  19. switch() Statement <?php switch ($country) { case ‘UK’ : $capital = ‘London’; break; case ‘US’ : $capital = ‘Washington’; break; case ‘FR’ : $capital = ‘Paris’; break; default : $capital = ‘Unknown’; break; } ?>

  20. Other Constructs • Ternary Operator $msg = $dialCount > 10 ? “Cannot connect after 10 attempts “ : “Dialing” ; • while() Loop while( condition is true) { do this; } • do() Loop do { dothis; } while (condition is true)

  21. for() Loop <?php for ($x = 0 ; $x <= 100 ; $x++) { echo “$x”; } ?>

  22. Using Arrays • Array is a complex variable that allows to store multiple values in a single variable • Can be thought of as a “container” variable which can contain one or more values <?php $flavors = array(‘Strawberry’, ‘Grape’ , “Vanilla” ,’Caramel’, “Choclate” ); ?>

  23. Using Arrays • Elements are accessed via index numbers the first index starts at 0 • PHP enables you to replace indices with user defined “ keys” to create a slightly different type of array . Each key is unique and corresponds to a single value. • Keys may be made up of any string characters

  24. Using Arrays • $Fruits = array("RED"=> "APPLE" , "YELLOW" =>"BANANA" ,"PURPLE" => "PLUM" , "GREEN"=>"GRAPE"); • This is an array variable containing 4 key value pairs • They are referred to as Hash or Associative Array

  25. Creating Arrays <?php $flavors[0] = “Strawberry”; $flavors[1] = “Grapes”; OR For Associative Array $Fruits[red] = “Apple”; $Fruits[green] = “Grape”;

  26. Modifying Array Elements • To Add an element to an Array , assign a value using the next available index number or key $flavors[5] = “mango”; OR $flavors [] = “mango”; • To modify an element of an array , assign a new value to the corresponding scalar variable . $flavors[0] = “Blueberry”;

  27. Processing Arrays with Loops <?php $flavors = array("Strawberry", "Grape" , "Vanilla" ,"Caramel", "Choclate" ); for($x=0; $x < sizeof($flavors); $x++) { echo “<li> $flavors[$x] “ ; } ?>

  28. The foreach() Loop • A new loop type introduced in PHP4.0 for the purpose of iterating over an array • This loop runs once for each element of the array • Unlike a for loop a foreach() loop does not need a counter or a call to sizeof(); it keeps track of it’s position in the array automatically

  29. The foreach() Loop <?php $num = array(10,20,30,40,50,60,70); foreach($num as $item) { echo "<li> $item "; } ?>

More Related