Sei sulla pagina 1di 13

PHP

Table of contents
1. PHP introduction
2. MySql & Installing Xamp
3. PHP Text Editor
4. Introduction PHP Basic Syntax
5. Introduction Variable, String Variables
6. Operators
7. Conditional Statements
7.1.1. If
7.1.2. Ifelse
7.1.3. If..elseifelse
7.1.4. Switch
8. Array
8.1.1. Numeric Array
8.1.2. Associative Array
8.1.3. Multidimensional Array
9. Loop
9.1.1. While loop
9.1.2. Do while
9.1.3. For
9.1.4. For each
10.Introduction of Functions
11.Introduction include and Require statement
12.Introduction Global Variables
13.Introduction server variables
14.Introduction GET method
15.Introduction POST method
16.Introduction REQUEST method
17.Introduction FILES method
18.Introduction Sessions
19.Introduction Destroy Session

20.Introduction Cookies
21.Introduction ISSET method
22.Introduction UNSET method
23.Introduction Empty method
24.Introduction Object Oriented programming
25.Introduction OOPs Class
26.Introduction OOPs Object
27.OOP destructor, Destroyer and clone object
28.Introduction OOPs inheritance
29.Create MySQL Database and tables
30.Connect to MySql Database
31.Select MySQL Database
32.SQL insert Statement/query
33.SQL select Statement/query
34.SQL delete Statement/query

PHP INTRODUCTION
Basically Javascript works on web browser while PHP works on a server thats why it
is called Server-Side Scripting Language.
PHP stands for :Hypertext Preprocessor
When PHP introduced it is known as Personal Homepage.
PHP is a server side scripting language like ASP.
Server side scripting language means its scripts executes on server. It does not
execute on our local machine.

PHP supports many database (MySQL, Informix, Oracle, Sybase, Solid,


Generic, ODBC, etc).

It is free to download and use.

It is used to enhance web pages.

Using PHP, you can do things like

Create username and password, Login pages, check details in a form, create
forums, picture galleries, surveys and many more things.

Why PHP????

PHP runs on different platforms(windows, Linux, Unix etc.)

PHP is compatible with almost all servers used today.

PHP is free to download from all PHP resources.(e.g. www.php.net )

PHP is easy to learn and easily executes on server side.

Difference between
Server Side Scripting
Server-Side script runs on the server

Client-Side Scripting
Client-Side Scripting runs on your

rather than on your computer

computer rather than on the server


Like HTML, JavaScript

What you should already know?


1. HTML
2. JavaScript
3. Basic concepts of programming
What you will need?
1. A server(Apache, IIIS, etc)
2. Computer with PHP Application
3. Text Editing Application

MySql & Installing Xamp

Installing XAMPP:
1. Install Xamp----This is basically a server
2. You can download it from google.
3. And you can easily install it.
After installing Xampp,

Open Xamp control panel


To check whether xamp is successfully installed or not.

Open Internet ExplorerOn the link side type localhostenterif the xamp page
is successfully open then it means, it is successfully installed.

Now go to Securityon a security page, you can find a link:


http:/localhost/security/xampsecurity.phpclick on it.
You can apply for username and password here.

Saving a PHP file


Write PHP program in NOTEPAD.
You cannot save PHP file anywhere.
To save a PHP file
Save aslocal diskxamp folderhtdocs folder
Filename.php
e.g. hello.php
To run a PHP file :Open internet explorertype:http//localhost/hello.php

PHP TEXT EDITORS


1. NOTEPAD

2. NOTEPAD++
3. DREAMWEAVER

INTRODUCTION PHP BASIC SYNTAX

PHP Syntax

Comment in PHP

Echo/Print

(1)PHP SYNTAX
<?php
PHP SYNTAX
?>
(2)COMMENTS IN PHP
e.g.
<html>
<head></head>
<?php
//Hello
?>
To give comment to multiple lines:
e.g.
<html>
<head></head>
<?php
/*This is my file
Hello
How are You?*/
?>

3. ECHO / PRINT
Echo and Print both are same. Both are used to display sentences in PHP.
e.g.
<html>
<head></head>
<?php
echo "This is an example";
?>
</html>

PHP VARIABLES AND STRING VARIABLES


How to write a variable in PHP?
(1) It starts with a $ sign.
(2) We can use _ to define a variable name
e.g. First_name
(3) Variables are case sensitive
e.g.
<?php
$x=3;
$y=4;
$result=$x+$y;
echo $result;
?>
STRING VARIABLES
In string variable, we can store a line, a content and a paragraph also.
e.g.
<?php
$txt="Hello How are you?";

echo $txt;
?>
Loops execute the statement again and again.
Loops are of four types:
(1) While Loop
(2) Do while Loop
(3) For Loop
(4) Foreach Loop
CONCATENATION OPERATOR
It is used to add two strings(Text). It is denoted by .
e.g.
<?php
$txt1="Hello How are you?";
$txt2="I am from Faridabad";
echo $txt1." ".$txt2;
?>

OPERATORS
There are 4 types of operators in PHP:(1) Arithmetic Operators
(2) Assignment Operators
(3) Incrementing/ Decrementing Operators
(4) Comparison Operator

Arithmetic Operator:
e.g.

2+2=4
32=1
3*3=9
4/2=2
5%2=1

e.g.
<?php
$x=4;
$y=3;
$z=$x+$y;
echo $z;
?>

Assignment Operator
It is used to Asssign a value
(i) x = y;
e.g. x = 2, y = 3
Then x = 3
(ii) x + = y

<?php

e.g.

$x=4;

x = 2, y = 3

$y=3;

then x = 2 + 3

$x=$x+$y;

x=5

echo $x;
?>

(iii) x - = y ; x = x y
X = 2, y = 3
X = 2 3 ; x = -1
(iv) x * y;

x=x* y

(v) x/ = y; x = x / y
(iv) x % = y; x = x % y

INCREMENTING/DECREMENTING OPERATOR
(i) + + x, x + + both are same
(ii) - - x, x - -

COMPARISON OPERATOR
X==y
It is used to compare
Note :- When there is single =, then it is assignment operator and if there is ==
then it is comparison operator.
e.g.
x = =y; x = 2, y = 3 (x = =y..>2 = = 3.>) False
Explanation:First it will check both the values of x and y i.e. whether they are equal or not. As in
the above case they are not equal, then it will return the answer in a Boolean
datatype e.g. True or False.
While Loop:
E.g.
<?php
$i=1;
while($i<5)
{
echo $i.<br>;
$i++;
}
?>

Do while Loop
In while loop, It check the condition, but in DOWHILE loop its doesnt check the
first condition.It directly executes it.
<?php
$v=1;
do
{
echo the number is =.$v.<br>;
$v++;
}while($v<=10)
?>
For Loop

For (initial;condition;increment/decrement)

BUILT-IN FUNCTIONS
(1) Include and require
(2) Include_once and require once
Include and Require:
Create a file names

Create a file names

<html>

<?php

<h2>Welcome to my
webpage</h2>

$x=10;

</html>

$v=$x+$y;

$y=20;

echo $v;
?>
And now if you want to add both the files you have to use a buit-in
function either INCLUDE or REQUIRE.

<?php
include first.php;
$x=10;
$y=20;
$v=$x+$y;
echo $v;
?>

The only difference between INCLUDE and REQUIRE i.e. if you use include,
and insert a file which does not exist. It will just give you a warning and
does not disturb the content of the file.But if you use REQUIRE then insert
an inexistible file, then it will block the content of the file.

INCLUDE_ONCE and REQUIRE_ONCE


Both are same as INCLUDE and REQUIRE.
INCLUDE ONCE:
If you use the INCLUDE statement two time, then it will display the result two time
like:
<?php
include first.php;
$x=10;
$y=20;
$v=$x+$y;
echo $v;
include first.php;
?>
But if you write include_once, then it will display result only one time.
<?php
include first.php;
$x=10;
$y=20;
$v=$x+$y;
echo $v;
include_once first.php;
?>

<?php
class account
{
var $accno;
var $balance=20;
function deposit($amt)
{
$this->balance=$this->balance+$amt;
echo $this->balance."<br>";
}
function withdraw($amt)
{
$this->balance=$this->balance-$amt;
echo $this->balance;
}
}
$obj=new account();
$obj->deposit(12);
$obj->withdraw(8);
?>

Potrebbero piacerti anche