Govt. College of & Technolgy, Bikaner: Practical Training Seminar Report
Govt. College of & Technolgy, Bikaner: Practical Training Seminar Report
Govt. College of & Technolgy, Bikaner: Practical Training Seminar Report
2015-16
INDEX
S.No. TOPICS
i.
ii.
iii.
1.
PAGE NO
Preface
Acknowledgement
4
5
Declaration
1. Introduction
7
7
7
7
8
8
8
2.2assignment Operators
2.3 Comparision Operators
2.4 Logical Operators
2.5 Concatenation Operators
9
9
9
9
10
10
3.
11
11
11
11
11
4.
PHP Array
12
12
12
12
2.
PHP Operators
2.1 Arithmetic Operators
5.
PHP Loops
5.1 while
5.2 do-while
5.3 for loop
5.4 for each
13
6.
PHP Function
13
7.
14
8.
15
9.
19
PHP DataBase
20
10.
PREFACE
Practical training seminar is an integral part of B.Tech. and each and every student has to train in
an institute or company before the 7th Semester.
This record is concerned about our practical training seminar during 7th Semester i.e. final year
of B.Tech. course. We have taken our Practical Training Seminar in PHP.
During this seminar, we got to learn many new things about the technology and its practical
implementation. This presentation proved to be a milestone in our knowledge of present
environment. Every say and every moment was an experience in itself, an experience which
theoretical study cant provide.
ACKNOWLEDGEMENT
DECLARATION
I, Rajesh kumar prajapat, Roll No 12ECTSC089, B.Tech (Semester VII) of the College of
Engineering & Technology, Bikaner (Raj.) hereby declare that the Practical Training Seminar
Report entitled PHP is an original work and data provided in the study is authentic to the best
if my knowledge. This report has not been submitted to any other institute for the award of any
other degree.
Rajesh kumar prajapat
(12ECTCS089)
Place:
Date:
This is to certify that above statement made by the candidate is correct to the best of our
knowledge.
Approved by:
1. INTRODUCTION
1.1 What is PHP?
PHP supports many databases (MySQL, Oracle, Sybase, Generic ODBC, etc.)
PHP is compatible with almost all servers used today (Apache, IIS, etc.)
//
/* and */
to make a large
<html>
<body>
<?php
//This is a comment
/*
This is a comment
block
*/
?>
</body>
</html>
A variable name should not contain spaces. If a variable name is more than one
word, it should be separated with an underscore ($my_string), or with
capitalization ($my String)
8
Ex:
<?php
$txt="Hello World";
echo $txt;
?>
PHP Operators
This section lists the different operators used in PHP.
Description
Addition
Subtraction
Multiplication
Division
++
Increment
--
Decrement
2.2
Example
x=2
x+2
x=2
5-x
x=4
x*5
15/5
5/2
5%2
10%8
10%2
x=5
x++
x=5
x--
Result
4
3
20
3
2.5
1
2
0
x=6
x=4
Assignment Operators:-
Operator
=
+=
-=
*=
Example
x=y
x+=y
x-=y
x*=y
Is The Same As
x=y
x=x+y
x=x-y
x=x*y
9
/=
.=
%=
2.3
x/=y
x.=y
x%=y
Comparison Operators:-
Operator
==
!=
<>
>
<
>=
<=
2.4
x=x/y
x=x.y
x=x%y
Description
is equal to
is not equal
is not equal
is greater than
is less than
is greater than or equal to
is less than or equal to
Example
5==8 returns false
5!=8 returns true
5<>8 returns true
5>8 returns false
5<8 returns true
5>=8 returns false
5<=8 returns true
Logical Operators:-
Operator
&&
Description
And
Example
x=6
y=3
(x < 10 && y > 1) returns true
||
Or
x=6
y=3
(x==5 || y==5) returns false
Not
x=6
y=3
!(x==y) returns true
Conditional statements are used to perform different actions based on different conditions.
switch statement - use this statement to select one of many blocks of code to
be executed
syntax:if (<condition>) {
//php code
}
11
else {
//php code
}
PHP Arrays
An array is a special variable, which can store multiple values in one single variable.
If you have a list of items (a list of car names, for example), storing the cars in single
variables could look like this:
$cars1="Saab";
$cars2="Volvo";
$cars3="BMW";
However, what if you want to loop through the cars and find a specific one? And what if
you had not 3 cars, but 300?The best solution here is to use an array!
An array can hold all your variable values under a single name. And you can access the
values by referring to the array name.Each element in the array has its own index so
that it can be easily accessed.
In PHP, there are three kind of arrays:
13
5 PHP Loops
Often when you write code, you want the same block of code to run over and over again
in a row. Instead of adding several almost equal lines in a script we can use loops to
perform a task like this.
In PHP, we have the following looping statements:
do...while - loops through a block of code once, and then repeats the loop as
long as a specified condition is true
14
6 PHP Functions
The real power of PHP comes from its functions.In PHP, there are more than 700 built-in
functions.
Give the function a name that reflects what the function does
The function name can start with a letter or underscore (not a number)
Example
A simple function that writes my name when it is called:
<html>
<body>
<?php
function writeName()
{
echo "Kai Jim Refsnes";
}
echo "My name is ";
writeName();
?>
</body>
</html>
Output:- My name is Kai Jim Refsnes
15
16
The PHP $_GET and $_POST variables are used to retrieve information from forms,
like user input.
17
However, because the variables are displayed in the URL, it is possible to bookmark the
page. This can be useful in some cases.
Note: The get method is not suitable for very large variable values. It should not be
used with values exceeding 2000 characters.
The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST,
and $_COOKIE.
The $_REQUEST function can be used to collect form data sent with both the GET and
POST methods.
Example
Welcome <?php echo $_REQUEST["fname"]; ?>!<br />
You are <?php echo $_REQUEST["age"]; ?> years old.
19
<html><body>
<?php
include("wrongFile.php");
echo "Hello World!";
?>
</body>
</html>
Error message:
Warning: include(wrongFile.php) [function.include]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5
Warning: include() [function.include]:
Failed opening 'wrongFile.php' for inclusion
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5
Hello World!
20
Exceptions are used to change the normal flow of a script if a specified error occurs
What is an Exception
With PHP 5 came a new object oriented way of dealing with errors.
Exception handling is used to change the normal flow of the code execution if a
specified error (exceptional) condition occurs. This condition is called an exception.
This is what normally happens when an exception is triggered:
Depending on the situation, the handler may then resume the execution from the
saved code state, terminate the script execution or continue the script from a
different location in the code
Multiple exceptions
Re-throwing an exception
Note: Exceptions should only be used with error conditions, and should not be used to
jump to another place in the code at a specified point
21
22
10PHP DATABASE
support variety of database management systems, including :
- MySQL
- PostgreSQL
- Oracle
- Microsoft Access
MySQL
very fast
very reliable
23
OUTPUT
25
26