Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Create username and password, Login pages, check details in a form, create
forums, picture galleries, surveys and many more things.
Why PHP????
Difference between
Server Side Scripting
Server-Side script runs on the server
Client-Side Scripting
Client-Side Scripting runs on your
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 Internet ExplorerOn the link side type localhostenterif the xamp page
is successfully open then it means, it is successfully installed.
2. NOTEPAD++
3. DREAMWEAVER
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>
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
<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.
<?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);
?>