Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mandakini Ayushi Infotech Mandakini Kumari 22 nd July 2012 PHP Basic.

Similar presentations


Presentation on theme: "Mandakini Ayushi Infotech Mandakini Kumari 22 nd July 2012 PHP Basic."— Presentation transcript:

1 Mandakini Ayushi Infotech Mandakini Kumari 22 nd July 2012 http://www.slideshare.net/mandakinikumari PHP Basic

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

4 Overview Object Database Connection Database Query Sessions & Cookies

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 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 What is PHP

7 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 Why PHP

8 The Stack Apache (lighttpd, IIS) MySQL (PostgresSQL, SQL Server, Oracle) PHP PHPMyAdmin for adminisering your SQL Database Linux (BSD, Mac OS, Windows, Solaris)

9 The Stack

10 Syntax <?php echo "Hello World"; ?>

11 PHP Variables <?php $txt="Hello World!"; $x=16; ?>

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. " "; $i++; }

21 For Loop for ($i=1; $i<=5; $i++) { echo "The number is ". $i. " "; }

22 Foreach Loop $x=array("one","two","three"); foreach ($x as $value) { echo $value. " "; }

23 Function

24 HTML Form Name: Age:

25 GET & POST Welcome You are years old. OR http://example.com/test.php?fname=Peter&age=37 Welcome. You are 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/", "ex ample.com", 1);

29 Thank you Contact me @ http://www.linkedin.com/pub/mandakini-kumari/18/93/935 https://www.facebook.com/mandakini.kumari


Download ppt "Mandakini Ayushi Infotech Mandakini Kumari 22 nd July 2012 PHP Basic."

Similar presentations


Ads by Google