php basic for vit university

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

Upload: mandakini-kumari

Post on 05-Dec-2014

581 views

Category:

Education


2 download

DESCRIPTION

Drupal enthusiasts in Chennai are coordination with IEEE organized a 3 day workshop. The Workshop introduced Drupal to students. Over 125 students participated this training program.

TRANSCRIPT

Page 1: Php basic for vit university

MandakiniAyushi Infotech

Mandakini Kumari22nd July 2012http://www.slideshare.net/mandakinikumari

PHP Basic

Page 2: Php basic for vit university

Overview A Brief HistoryWhat is PHPWhy PHPPHP StackPHP SyntaxVariablesPHP StringPHP Operators

Page 3: Php basic for vit university

Overview PHP ArraysPHP If...ElsePHP SwitchPHP WhileFor LoopForeachFunctionForm,Get,Post

Page 4: Php basic for vit university

Overview ObjectDatabase ConnectionDatabase QuerySessions & Cookies

Page 5: Php basic for vit university

A brief history• Created by Rasmus Lerdorf in 1995

• PHP: Hypertext Preprocessor• PHP interpreters available on 32-bit and 64-bit operating systems

Page 6: Php basic for vit university

• 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

Page 7: Php basic for vit university

• 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

Page 8: Php basic for vit university

The Stack•Apache (lighttpd, IIS)•MySQL (PostgresSQL, SQL Server, Oracle)

•PHP•PHPMyAdmin for adminisering your SQL Database

•Linux (BSD, Mac OS, Windows, Solaris)

Page 9: Php basic for vit university

The Stack

Page 10: Php basic for vit university

Syntax

<?phpecho "Hello World";?>

Page 11: Php basic for vit university

PHP Variables

<?php

$txt="Hello World!";

$x=16;

?>

Page 12: Php basic for vit university

PHP Variable Types Local Global Static Parameter

Page 13: Php basic for vit university

PHP Global Variable$a = 5; $b = 10;

function myTest()

{

global $a, $b;

$b = $a + $b;

}

myTest();

echo $b;

Page 14: Php basic for vit university

PHP Local Variable

$a = 5; // global scope

function myTest()

{

echo $a; // local scope

}

myTest();

Page 15: Php basic for vit university

PHP Static & Parameters

static $rememberMe;

function myTest($para1,$para2)

{

}

Page 16: Php basic for vit university

Operatorsx + 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

Page 17: Php basic for vit university

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];

Page 18: Php basic for vit university

If else Statementif (condition)

{

code to be executed if condition is true;

}

else

{

code to be executed if condition is false;

}

Page 19: Php basic for vit university

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"; }

Page 20: Php basic for vit university

While Statement$i=1;

while($i<=5)

{

echo "This number is " . $i . "<br />";

$i++;

}

Page 21: Php basic for vit university

For Loop

for ($i=1; $i<=5; $i++) { echo "The number is " . $i . "<br />";

}

Page 22: Php basic for vit university

Foreach Loop$x=array("one","two","three");

foreach ($x as $value)

{

echo $value . "<br />";

}

Page 23: Php basic for vit university

Function<?php

function add($x,$y){$total=$x+$y;return $total;}echo "1 + 16 = " . add(1,16);?>

Page 24: Php basic for vit university

HTML Form<form action="welcome.php"

method="post">Name: <input type="text" name="fname" />Age: <input type="text" name="age" /><input type="submit" />

</form>

Page 25: Php basic for vit university

GET & POST Welcome <?php echo $_POST["fname"]; ?>

You are <?php echo $_POST["age"]; ?> years old.

OR

http://example.com/test.php?fname=Peter&age=37

Welcome <?php echo $_GET["fname"]; ?>.<br />You are <?php echo $_GET["age"]; ?> years old!

Page 26: Php basic for vit university

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);

Page 27: Php basic for vit university

Mysql Query

$sql="INSERT INTO Persons (FirstName, Age)VALUES('$_POST[fname], '$_POST[age]')";

mysql_query($sql);

Select * FROM Persons

Update/Delete

Page 28: Php basic for vit university

Session & Cookiesession_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/", "example.com", 1);

Page 29: Php basic for vit university

Thank you

Contact me @

http://www.linkedin.com/pub/mandakini-kumari/18/93/935

https://www.facebook.com/mandakini.kumari