LAMP Architecture
-
Upload
dean-gilliam -
Category
Documents
-
view
58 -
download
0
description
Transcript of LAMP Architecture
![Page 1: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/1.jpg)
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
![Page 2: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/2.jpg)
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.
![Page 3: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/3.jpg)
Learning PHP
Learning Basics
![Page 4: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/4.jpg)
Embedding PHP in HTML There are three possibilities <?php ….PHP code … ?> <? …..PHP Code ….. ?> <% …..PHP Code…. %> <script language = “php”> ……PHP Code </ script >
![Page 5: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/5.jpg)
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 BrowserHow PHP Works ends with ; Code blocks are enclosed in { } Comments begin with // or # (Single line) and /* …. */ (For Multi
Line)
![Page 6: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/6.jpg)
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
![Page 7: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/7.jpg)
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
![Page 8: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/8.jpg)
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
![Page 9: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/9.jpg)
Data Types
Boolean Integer Float String Array Object Resource NULL
![Page 10: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/10.jpg)
Assigning & Using Variable Values
<?php
$age = $dob +15;
?> <?php
$today = “Jan 05 2004”;
echo “today is $today “ ;
?>
![Page 11: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/11.jpg)
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) ;
?>
![Page 12: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/12.jpg)
Detecting the Data type
Specialized functions is_bool is_string is_numeric is_float is_int is_null is_array is_object
![Page 13: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/13.jpg)
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 NULLecho gettype($me);
?>
![Page 14: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/14.jpg)
Using Operators <?php
$num1 = 101;
$num2 = 5;
$sum = $num1 + $num2;
$diff = $num1 - $num2;
$product = $num1 * $num2;
$quotient = $num1 / num2 ;
$remainder = $num1 % $num2 ;
?>
![Page 15: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/15.jpg)
Using OperatorsOperators What It does
. Concatenation
== Equal to
=== Equal to and of the same type
!== Not Equal to or not of the same type
<> aka != Not Equal to
&& Logical AND
|| Logical OR
XOR Logical XOR
! Logical NOT
++ Increment
-- Decrement
![Page 16: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/16.jpg)
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 );
?>
![Page 17: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/17.jpg)
if() Statement<?php
if (conditional test){ do this;}else{ do this;}?>
![Page 18: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/18.jpg)
If elseif PHP also provides if-elseif-else() construct <?phpif (conditional test){ do this;}elseif (conditional test #1) { do this;}………..elseif (conditional test #N) { do this;}
else{ do this ;} ?>
![Page 19: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/19.jpg)
switch() Statement<?php switch ($country) { case ‘UK’ : $capital = ‘London’; break;
case ‘US’ : $capital = ‘Washington’; break;
case ‘FR’ : $capital = ‘Paris’; break;
default : $capital = ‘Unknown’; break;}?>
![Page 20: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/20.jpg)
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)
![Page 21: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/21.jpg)
for() Loop
<?php
for ($x = 0 ; $x <= 100 ; $x++)
{
echo “$x”;
}
?>
![Page 22: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/22.jpg)
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” );
?>
![Page 23: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/23.jpg)
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
![Page 24: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/24.jpg)
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
![Page 25: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/25.jpg)
Creating Arrays
<?php
$flavors[0] = “Strawberry”;
$flavors[1] = “Grapes”;
OR For Associative Array
$Fruits[red] = “Apple”;
$Fruits[green] = “Grape”;
![Page 26: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/26.jpg)
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”;
![Page 27: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/27.jpg)
Processing Arrays with Loops
<?php$flavors = array("Strawberry", "Grape" ,
"Vanilla" ,"Caramel", "Choclate" ); for($x=0; $x < sizeof($flavors); $x++){ echo “<li> $flavors[$x] “ ;}?>
![Page 28: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/28.jpg)
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
![Page 29: LAMP Architecture](https://reader031.fdocuments.us/reader031/viewer/2022020713/56812b12550346895d8f04b1/html5/thumbnails/29.jpg)
The foreach() Loop
<?php$num = array(10,20,30,40,50,60,70);
foreach($num as $item){ echo "<li> $item "; }?>