0% found this document useful (0 votes)
23 views51 pages

PHP Training

PHP is a server-side scripting language used for web development. It allows variables, functions, classes, and objects. PHP can interact with MySQL databases using functions like mysqli_connect(), mysqli_query(), and mysqli_fetch_array(). The document provides examples of PHP syntax like variables, data types, conditionals, loops, arrays, and functions. It also covers OOP concepts like classes, inheritance, and interfaces.

Uploaded by

Firstnaukri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views51 pages

PHP Training

PHP is a server-side scripting language used for web development. It allows variables, functions, classes, and objects. PHP can interact with MySQL databases using functions like mysqli_connect(), mysqli_query(), and mysqli_fetch_array(). The document provides examples of PHP syntax like variables, data types, conditionals, loops, arrays, and functions. It also covers OOP concepts like classes, inheritance, and interfaces.

Uploaded by

Firstnaukri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

PHP Training

PHP Training

What is PHP Used For?

PHP is a general-purpose server-side scripting


language originally designed for web
development to produce dynamic web pages

PHP can interact with My!" databases



What is PHP?

PHP ## $PHP Hyperte%t Preprocessor$

&pen-source' server-side scripting language

"oosely Typed cripting "anguage

(nterpreted at runtime )use an opcode cache*

+ommonly used to build web applications



,ariable -ssignment
.?php
/hello # 0Hello' ,T +ode +amp102
echo /hello2
?3

+omments )&ne "ine*
.?php
44 - one line comment
5 -nother one line comment
?3

+omments )Multi "ine*
.?php
46
- multi-line comment
64
?3

+omments )7oc 8loc*
.?php
466
6 This function does nothing
6
6 9param string /bar
6 9return void
64
function foo)/bar* :;
?3

7ata Types
.?php
/isPhpProgrammer # true2 44 boolean
/how&ld(sPhp # <=2 44 integer
/pi # >1<?2 44 @oat
/event # 0,T +ode +amp02 44 string
?3

+onditionals )(f-Then-Alse-(f*
.?php
if )false* :
echo 0Bo02
; elseif )false* :
echo 0Bo02
; else :
echo 0Ces02
;
?3

witch
.?php
switch )0PHP0* :
case 0Duby0E
echo 0Bo02
breaF2
case 0PHP0E
echo 0Ces02
breaF2
;
?3

&perators )-rithmatic*
.?php
/a # <G2
/b # /a H <2 44<<
/c # /a - <2 44I
/d # /a 6 =2 44=G
/e # /a 4 J2 44=
/f # /a K >2 44<
?3

tring +oncatenation
.?php
/mytring # 0foo0 1 0bar02 44 foobar
/mytring 1# 0baL02 44 foobarbaL
?3

+omparison )AMuivalence*
.?php
if )J ## >* : echo 0Bo02 ;
if )> ## 0>0* : echo 0Ces02 ;
if )J N# >* : echo 0Ces02 ;
?3

+omparison )(dentity*
.?php
if )> ### 0>0* : echo 0Bo02 ;
if )> ### >* : echo 0Ces02 ;
if )> N## ?* : echo 0Ces02 ;
?3

"ogical &perators
.?php
44 B&T
if )Ntrue* : echo 0Bo02 ;
44 -B7
if )true OO false* : echo 0Bo02 ;
44 &D
if )true PP false* : echo 0Bo02 ;
?3

"iteral ingle !uotes
.?php
/% # J2
echo 0( ate /% cooFies102
44 ( ate /% cooFies1
?3

7ouble !uotes
.?php
/% # J2
echo Q( ate /% cooFies1Q2
44 ( ate J cooFies1
?3

"iteral 7ouble !uotes
.?php
/% # J2
echo Q( ate R/% cooFies1Q2
44 ( ate /% cooFies1
?3

+urly 8race 7ouble !uotes
.?php
/% # J2
echo Q( ate :/%; cooFies1Q2
44 ( ate J cooFies1
?3

+onstants
.?php
deSne)0HA""&0' 0Hello' +ode +amp0*2
echo HA""&2 44 Hello' +ode +amp
?3

+onstants )-s of PHP =1>*
.?php
const HA""& # 0Hello' +ode +amp02
echo HA""&2 44 Hello' +ode +amp
?3

-rrays )-utomatic (nde%ing*
.?php
/fooTU # 0bar02 44 TGU #3 bar
/fooTU # 0baL02 44 T<U #3 baL
?3

-rrays )A%plicit (nde%ing*
.?php
/fooTGU # 0bar02 44 TGU #3 bar
/fooT<U # 0baL02 44 T<U #3 baL
?3

-rrays )+onstruct with -utomatic (nde%ing*
.?php
/foo # array)
0bar0' 44 TGU #3 bar
0baL0' 44 T<U #3 baL
*2
?3

-rrays )+onstruct with A%plicit (nde%ing*
.?php
/foo # array)
G #3 0bar0' 44 TGU #3 bar
< #3 0baL0' 44 T<U #3 baL
*2
?3

-rrays )+onstruct with -rbitary (nde%ing*
.?php
/foo # array)
< #3 0bar0' 44 T<U #3 bar
J #3 0baL0' 44 TJU #3 baL
*2
?3

-rrays )-ssociative with A%plicit (nde%ing*
.?php
/fooT0a0U # 0bar02 44 TaU #3 bar
/fooT0b0U # 0baL02 44 TbU #3 baL
?3

-rrays )-ssociative +onstruct*
.?php
/foo # array)
0a0 #3 0bar0' 44 TaU #3 bar
0b0 #3 0baL0' 44 TbU #3 baL
*2
?3

(terators )While*
.?php
/% # G2
while )/% . =* :
echo 0102
/%HH2
;
?3

(terators )For*
.?php
for )/% # G2 /% . =2 /%HH* :
echo 0102
;
?3

(terators )Foreach*
.?php
/% # array)G' <' J' >' ?*2
foreach )/% as /y* :
echo /y2
;
?3

(terators )Foreach V Wey4,alue Pair*
.?php
/talFs # array)
0php0 #3 0(ntro to PHP0'
0ruby0 #3 0(ntro to Duby0'
*2
foreach )/talFs as /id #3 /name* :
echo Q/name is talF (7 /id1Q2
echo PHPXA&"2
;
?3

Functions )8uilt-(n*
.?php
echo strlen)0Hello0*2 44 =
echo trim)0 Hello 0*2 44 Hello
echo count)array)G' <' J' >**2 44 ?
echo uniMid)*2 44 ?cYaZZZG=<Id=
echo mtXrand)G' I*2 44 >
echo serialiLe)?J*2 44 iE?J2
echo [sonXencode)array)0a0 #3 0b0**2
44 :QaQEQbQ;
?3

Functions )User 7eSned*
.?php
function add)/%' /y*
:
return /% H /y2
;
echo add)J' ?*2 44 Z
?3

-nonymous Functions 4 +losures )PHP =1>*
.?php
/sayHi # function )*
:
return 0Hi02
;2
echo /sayHi)*2 44 Hi
?3

+allbacFs
.?php
/values # array)>' \' J*2
usort)/values' function )/a' /b* :
if )/a ## /b* : return G2 ;
return )/a . /b* ? -< E <2
;*2
46 TGU #3 J
T<U #3 >
TJU #3 \ 64
?3

+lasses O &b[ects

+lass 7eclaration
.?php
class +ar
:
;
?3

Property 7eclaration
.?php
class +ar
:
private /Xhasunroof # true2
;
?3

Method 7eclaration
.?php
class +ar
:
public function hasunroof)*
:
return /this-3Xhasunroof2
;
;
?3

+lass +onstants
.?php
class +ar
:
const AB](BAX,? # 0,?02
const AB](BAX,Z # 0,Z02
const AB](BAX,Y # 0,Y02
;
echo +arEEAB](BAX,Z2 44 ,Z
?3

&b[ect (nstantiation O Member -ccess
.?php
/my+ar # new +ar)*2
if )/my+ar-3hasunroof)** :
echo 0CayN02
;
?3

+lass (nheritance
.?php
class +hevy e%tends +ar
:
;
?3

(nterfaces
.?php
interface ,ehicle
:
public function hasunroof)*2
;
?3

(mplementing (nterfaces
.?php
class +ar implements ,ehicle
:
public function hasunroof)*
:
return /this-3Xhasunroof2
;
;
?3

My!" Functions

mysMlXconnect)*

mysMlXselectXdb)*

mysMlXMuery)*

mysMlXfetchXarray)*

mysMlXnumXrows)*

mysMlXclose

P7& )PHP 7ata &b[ect*

My!"i

P7& vs My!"i

P7& vs My!"i )7atabase upport*

PA-D

PHP A%tension and -pplication Depository

PacFage manager

PA+" )PHP A%tension +ommunity "ibrary*



!uestions?
!uestions?

Deferences

httpE44php1net4

httpE44www1mysMl1com4

httpE44net1tutsplus1com4tutorials4php4
pdo-vs-mysMli-which-should-you-use4

httpE44php1net4pdoXmysMl

httpE44php1net4manual4en4language1oop=1php

-nd' many more111

You might also like