Download - Php basic for vit university
![Page 1: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/1.jpg)
MandakiniAyushi Infotech
Mandakini Kumari22nd July 2012http://www.slideshare.net/mandakinikumari
PHP Basic
![Page 2: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/2.jpg)
Overview A Brief HistoryWhat is PHPWhy PHPPHP StackPHP SyntaxVariablesPHP StringPHP Operators
![Page 3: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/3.jpg)
Overview PHP ArraysPHP If...ElsePHP SwitchPHP WhileFor LoopForeachFunctionForm,Get,Post
![Page 4: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/4.jpg)
Overview ObjectDatabase ConnectionDatabase QuerySessions & Cookies
![Page 5: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/5.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/6.jpg)
• 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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/7.jpg)
• 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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/8.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/9.jpg)
The Stack
![Page 10: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/10.jpg)
Syntax
<?phpecho "Hello World";?>
![Page 11: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/11.jpg)
PHP Variables
<?php
$txt="Hello World!";
$x=16;
?>
![Page 12: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/12.jpg)
PHP Variable Types Local Global Static Parameter
![Page 13: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/13.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/14.jpg)
PHP Local Variable
$a = 5; // global scope
function myTest()
{
echo $a; // local scope
}
myTest();
![Page 15: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/15.jpg)
PHP Static & Parameters
static $rememberMe;
function myTest($para1,$para2)
{
}
![Page 16: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/16.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/17.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/18.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/19.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/20.jpg)
While Statement$i=1;
while($i<=5)
{
echo "This number is " . $i . "<br />";
$i++;
}
![Page 21: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/21.jpg)
For Loop
for ($i=1; $i<=5; $i++) { echo "The number is " . $i . "<br />";
}
![Page 22: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/22.jpg)
Foreach Loop$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br />";
}
![Page 23: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/23.jpg)
Function<?php
function add($x,$y){$total=$x+$y;return $total;}echo "1 + 16 = " . add(1,16);?>
![Page 24: Php basic for vit university](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/24.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/25.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/26.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/27.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/28.jpg)
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](https://reader038.vdocuments.us/reader038/viewer/2022102922/54843722b4af9f640d8b4ad6/html5/thumbnails/29.jpg)
Thank you
Contact me @
http://www.linkedin.com/pub/mandakini-kumari/18/93/935
https://www.facebook.com/mandakini.kumari