SlideShare a Scribd company logo
1 of 60
Download to read offline
your name 
your 
caption 
here 
Web Development using PHP & MySQL 
R S Wadawadagi 
Asst. Prof 
Dept of MCA, BEC, Bagalkot
your name 
your 
caption 
here 
Request / Response Cycle 
JavaScript 
HTML 
GET 
AJAX HTTP 
CSS 
Request 
Response 
POST 
PHP 
MySqlMVC 
JSP 
Cookies
your name 
Open Source Technologies 
your 
caption 
here 
LLIINNUUXX -- LLiinnuuxx iiss oonnee ooff ppooppuullaarr vveerrssiioonn ooff UUNNIIXX ooppeerraattiinngg SSyysstteemm.. IItt iiss ooppeenn ssoouurrccee aass 
iittss ssoouurrccee ccooddee iiss ffrreeeellyy aavvaaiillaabbllee.. IItt iiss ffrreeee ttoo uussee.. LLiinnuuxx wwaass ddeessiiggnneedd ccoonnssiiddeerriinngg UUNNIIXX 
ccoommppaattiibbiilliittyy.. IItt''ss ffuunnccttiioonnaalliittyy lliisstt iiss qquuiittee ssiimmiillaarr ttoo tthhaatt ooff UUNNIIXX.. 
AAPPAACCHHEE -- TThhee AAppaacchhee HHTTTTPP SSeerrvveerr PPrroojjeecctt iiss aa ccoollllaabboorraattiivvee ssooffttwwaarree ddeevveellooppmmeenntt 
eeffffoorrtt aaiimmeedd aatt ccrreeaattiinngg aa rroobbuusstt,, ccoommmmeerrcciiaall--ggrraaddee,, ffeeaattuurreeffuull,, aanndd ffrreeeellyy--aavvaaiillaabbllee 
ssoouurrccee ccooddee iimmpplleemmeennttaattiioonn ooff aann HHTTTTPP ((WWeebb)) sseerrvveerr.. 
MMYYSSQQLL -- MMyySSQQLL iiss oonnee ooff tthhee mmoosstt ppooppuullaarr ffrreeee aanndd ooppeenn ssoouurrccee ddaattaabbaassee eennggiinneess iinn 
tthhee mmaarrkkeett ppllaaccee.. MMyySSQQLL ppoowweerrss FFaacceebbooookk,, YYaahhoooo!!,, WWoorrddPPrreessss,, DDrruuppaall,, JJoooommllaa,, aanndd 
mmiilllliioonnss ooff ootthheerr ddyynnaammiicc wweebb ssiitteess.. 
PPHHPP -- PPHHPP iiss tthhee mmoosstt wwiiddeellyy uusseedd ssccrriippttiinngg llaanngguuaaggee ffoorr wweebb pprrooggrraammmmiinngg.. PPHHPP 
eexxtteennddss HHTTMMLL ppaaggeess bbyy aaddddiinngg sseerrvveerr--eexxeeccuutteedd ccooddee sseeggmmeennttss ttoo HHTTMMLL ppaaggeess.. TThhee 
oouuttppuutt ooff tthhee eexxeeccuuttiioonn ooff tthhee PPHHPP ccooddee iiss mmeerrggeedd iinnttoo tthhee HHTTMMLL ppaaggee..
your name 
your 
caption 
here 
Setting up a Development Server 
What we need.....? 
1) Apache Web Server (Includes PHP) 
2) MySql Database Server 
3) MySql Administation Software (PhpMyAdmin) 
We could install all this by hand... 
All-In-One Pre-Packaged 
LAMP - Linux, Apache, MySQL, and PHP 
Prefer: MAMP on Macintosh XAMPP on Windows
your name 
your 
caption 
here 
Programmer Editor 
Do not use Word, TextEdit, or NotePad 
 Programmer Editor 
 Linux: Gedit, Bluefish, Geany 
 Windows: NotePad++ 
 Macintosh: TextWrangler 
 Feel free to use an Integrated Development 
Environment such Eclipse, etc. if you have experience.
your name 
your 
caption 
here 
The History of PHP 
 PPHHPP-- PPHHPP HHyyppeerrtteexxtt PPrreepprroocceessssoorr 
 RRaassmmuuss LLeerrddoorrff ((11999944)) 
 NNoott aa ttrraaiinneedd ccoommppuutteerr sscciieennttiisstt 
 CCoonnssuullttaanntt bbuuiillddiinngg ddyynnaammiicc wweebb ssiitteess -- ggoott ttiirreedd ooff 
ddooiinngg tthhee ssaammee tthhiinngg oovveerr aanndd oovveerr iinn CC 
 RReeuussaabbllee bbiittss ++ HHTTMMLL TTeemmppllaatteess
your name 
your 
caption 
here 
Introduction to PHP 
 SSyynnttaaxx iiss iinnssppiirreedd bbyy CC && ppeerrll 
 CCuurrllyy bbrraacceess,, sseemmiiccoolloonnss,, nnoo ssiiggnnffiiccaanntt wwhhiitteessppaaccee 
 DDoollllaarr ssiiggnnss ttoo ssttaarrtt vvaarriiaabbllee nnaammeess,, aassssoocciiaattiivvee aarrrraayyss 
 EExxtteennddss HHTTMMLL ttoo aadddd sseeggmmeennttss ooff PPHHPP wwiitthhiinn aann HHTTMMLL ffiillee 
 PPHHPP ffiillee rruunnss oonn wweebb sseerrvveerr,, iinnppuuttss PPHHPP ccooddee,, ccoommppiilleess ttoo bbyytteeccooddee,, 
oouuttppuuttss WWeebb PPaaggeess.. 
 CCrreeaatteess DDyynnaammiicc WWeebb PPaaggeess,, uussiinngg SSeerrvveerr SSiiddee SSccrriippttiinngg.. ((lliikkee ..aasspp,, 
..jjsspp,, ppeerrll)).. CClliieennttss ““RRuunn”” tthheessee wweebb ppaaggeess wwhheenn vviissiitteedd..
your name 
your 
caption 
here 
Features of PHP 
 HHTTTTPP aauutthheennttiiccaattiioonn wwiitthh PPHHPP 
 CCooookkiieess 
 SSeessssiioonnss 
 DDeeaalliinngg wwiitthh XXFFoorrmmss 
 HHaannddlliinngg ffiillee uuppllooaaddss 
 UUssiinngg rreemmoottee ffiilleess 
 CCoonnnneeccttiioonn hhaannddlliinngg 
 PPeerrssiisstteenntt DDaattaabbaassee CCoonnnneeccttiioonnss 
 SSaaffee MMooddee 
 CCoommmmaanndd lliinnee uussaaggee —— UUssiinngg PPHHPP ffrroomm tthhee ccoommmmaanndd lliinnee 
 GGaarrbbaaggee CCoolllleeccttiioonn 
 DDTTrraaccee DDyynnaammiicc TTrraacciinngg
your name 
your 
caption 
here 
<!DOCTYPE html> 
<html> 
<body> 
<h1> Hello from BECBGK''s home Page </h1> 
<p> 
<?php 
echo "<h2>","My first PHP script...!","</h2>"; 
$sum = 30 + 40; 
echo "<h2>","The sum of 30 and 40 is $sum","</h2>"; 
?> 
</p> 
</body> 
</html> 
My First PHP Script
your name 
your 
caption 
here 
<!DOCTYPE html> 
<html> 
<body> 
<h1>Hello from BECBGK''s home Page</h1> 
<p> 
<?php 
echo "<h2>","My first PHP script...!","</h2>"; 
$sum = 30 + 40; 
echo "<h2>","The sum of 30 and 40 is $sum","</h2>"; 
?> 
</p> 
</body> 
</html> 
My First PHP Script
your name 
your 
caption 
here 
PHP From the Command Line 
 You ccaann rruunn PPHHPP ffrroomm tthhee 
ccoommmmaanndd lliinnee -- tthhee oouuttppuutt 
ssiimmppllyy ccoommeess oouutt oonn tthhee 
tteerrmmiinnaall 
 IItt ddooeess nnoott hhaavvee ttoo bbee ppaarrtt 
ooff aa rreeqquueesstt--rreessppoonnssee ccyyccllee 
<?php 
echo("Hello 
World!"); 
echo("n"); 
?>
your name 
Keywords 
your 
caption 
here 
aabbssttrraacctt aanndd aarrrraayy(()) aass bbrreeaakk ccaassee 
ccaattcchh ccllaassss cclloonnee ccoonnsstt ccoonnttiinnuuee 
ddeeccllaarree ddeeffaauulltt ddoo eellssee eellsseeiiff 
eenndd ddeeccllaarree eennddffoorr eennddffoorreeaacchh eennddiiff 
eennddsswwiittcchh eennddwwhhiillee eexxtteennddss ffiinnaall ffoorr 
ffoorreeaacchh ffuunnccttiioonn gglloobbaall ggoottoo iiff iimmpplleemmeennttss 
iinntteerrffaaccee iinnssttaanncceeooff nnaammeessppaaccee nneeww oorr 
pprriivvaattee pprrootteecctteedd ppuubblliicc ssttaattiicc sswwiittcchh 
$$tthhiiss tthhrrooww ttrryy uussee vvaarr 
wwhhiillee xxoorr
your name 
Variable Names 
your 
caption 
here 
 Start with a dollar sign ($) ffoolllloowweedd bbyy aa lleetttteerr oorr 
uunnddeerrssccoorree,, ffoolllloowweedd bbyy aannyy nnuummbbeerr ooff lleetttteerrss,, nnuummbbeerrss,, 
oorr uunnddeerrssccoorreess 
 CCaassee mmaatttteerrss 
$$aabbcc == 1122;; $$ttoottaall == 00;; $$llaarrggeesstt__ssoo__ffaarr == 00;; 
aabbcc == 1122;; $$22pphhpp == 00;; $$bbaadd--ppuunncc == 00;;
your name 
Expressions 
your 
caption 
here 
 Completely nnoorrmmaall lliikkee ootthheerr llaanngguuaaggeess (( ++ -- // ** )) 
 MMoorree aaggrreessssiivvee iimmpplliicciitt ttyyppee ccoonnvveerrssiioonn 
<<??pphhpp 
$$xx == ""1155"" ++ 2277;; 
eecchhoo(($$xx));; 4422 
eecchhoo((""nn""));; 
??>>
your name 
Operators of Note 
your 
caption 
here 
 IInnccrreemmeenntt // DDeeccrreemmeenntt (( ++++ ---- )) 
 SSttrriinngg ccoonnccaatteennaattiioonn (( .. )) 
 EEqquuaalliittyy (( ==== !!== )) 
 IIddeennttiittccaall (( ====== !!==== )) 
 TTeerrnnaarryy (( ?? : )) 
 SSiiddee--eeffffeecctt AAssssiiggnnmmeenntt (( ++== --== ..== eettcc..)) 
 SSttrriinngg ooppeerraattoorrss (( ..,, ..==)) 
 AArrrraayy ooppeerraattoorrss(( TToo ccoommppaarree ttwwoo aarrrraayyss)) 
 IIggnnoorree tthhee rraarreellyy--uusseedd bbiittwwiissee ooppeerraattoorrss (( >>>> <<<< ^^ || && ))
your name 
your 
caption 
here 
Output statements 
 ““eecchhoo”” iiss aa llaanngguuaaggee ccoonnssttrruucctt -- 
ccaann bbee ttrreeaatteedd lliikkee aa ffuunnccttiioonn wwiitthh 
oonnee ppaarraammeetteerr.. WWiitthhoouutt 
ppaarreenntthheessiiss,, iitt aacccceeppttss mmuullttiippllee 
PPaarraammeetteerrss.. 
““pprriinntt”” iiss aa ffuunnccttiioonn -- oonnllyy oonnee 
ppaarraammeetteerr bbuutt ppaarreenntthheessiiss aarree 
ooppttiioonnaall ssoo iitt ccaann llooookk lliikkee aa 
llaanngguuaaggee ccoonnssttrruucctt 
<?php 
$x = "15" + 27; 
echo $x; 
echo("n"); 
echo $x, "n"; 
print $x; 
print "n"; 
print($x); 
print("n"); 
?> 
lab2.php
your name 
your 
caption 
here 
Conditional - if 
 Logical operators ( == != << >> <<== >>== aanndd oorr !! )) 
 CCuurrllyy bbrraacceess 
<?php 
$ans = 42; 
if ( $ans == 42 ) { 
print "Hello world!n"; Hello world! 
} else { 
print "Wrong answern"; 
} 
?>
your name 
your 
caption 
here 
Branching & bounding 
 iiff ssttaatteemmeenntt -- eexxeeccuutteess ssoommee ccooddee oonnllyy iiff aa ssppeecciiffiieedd 
ccoonnddiittiioonn iiss ttrruuee 
 iiff......eellssee ssttaatteemmeenntt -- eexxeeccuutteess ssoommee ccooddee iiff aa ccoonnddiittiioonn iiss 
ttrruuee aanndd aannootthheerr ccooddee iiff tthhee ccoonnddiittiioonn iiss ffaallssee 
 iiff......eellsseeiiff........eellssee ssttaatteemmeenntt -- sseelleeccttss oonnee ooff sseevveerraall bblloocckkss ooff 
ccooddee ttoo bbee eexxeeccuutteedd 
 sswwiittcchh ssttaatteemmeenntt -- sseelleeccttss oonnee ooff mmaannyy bblloocckkss ooff ccooddee ttoo 
bbee eexxeeccuutteedd
your name 
your 
caption 
here 
Associative Arrays 
 Py Like Pytthhoonn DDiiccttoonnaarriieess++LLiissttss -- bbuutt mmoorree 
ppoowweerrffuull 
CCaann bbee kkeeyy ==>> vvaalluuee oorr ssiimmppllyy iinnddeexxeedd bbyy 
nnuummbbeerrss 
 IIggnnoorree ttwwoo--ddiimmeennssiioonnaall aarrrraayyss ffoorr nnooww......
your name 
your 
caption 
here 
Integer Indices 
<?php 
$stuff = array("Hi", "There"); 
echo $stuff[0], "n"; 
echo $stuff[1], "n"; 
?> 
Hi 
There
your name 
your 
caption 
here 
Integer Indices 
<?php 
$stuff = Array(); 
$stuff[] = "Hello"; 
$stuff[] = "World"; 
echo $stuff[1], "n"; 
?> 
World
your name 
your 
caption 
here 
Key / Value 
<?php 
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); 
echo "Peter is " . $age[''Peter''] . " years old."; 
?>
your name 
your 
caption 
here 
Dumping an Array 
 The function print_r() dduummppss oouutt PPHHPP ddaattaa -- iitt iiss uusseedd mmoossttllyy ffoorr 
ddeebbuuggggiinngg 
<<??pphhpp 
$$ssttuuffff == aarrrraayy((""nnaammee"" ==>> ""XXYYZZ"",,""ccoouurrssee"" ==>> ""MMCCAA""));; 
pprriinntt__rr(($$ssttuuffff));; 
??>>
your name 
your 
caption 
here 
Looping 
 while ­­loops 
through a block of code as long 
as the specified condition is true 
 do...while ­­loops 
through a block of code 
once, and then repeats the loop as long as the 
specified condition is true 
 for ­­loops 
through a block of code a 
specified number of times 
 foreach ­­loops 
through a block of code for 
each element in an array
your name 
your 
caption 
here 
Looping Through an associative array 
<?php 
$stuff = array("name" => "XYZ","course" => 
"MCA"); 
foreach($stuff as $k => $v ) { 
echo "Key=",$k," Val=",$v,"n"; 
} 
?> 
KKeeyy==nnaammee VVaall==XXYYZZ 
KKeeyy==ccoouurrssee VVaall==MMCCAA
your name 
your 
caption 
here 
Strings 
 String literals ccaann uussee ssiinnggllee qquuootteess oorr ddoouubbllee qquuootteess 
 TThhee bbaacckkssllaasshh (()) iiss uusseedd aass aann ""eessccaappee"" cchhaarraacctteerr 
 SSttrriinnggss ccaann ssppaann mmuullttiippllee lliinneess -- tthhee nneewwlliinnee iiss ppaarrtt ooff tthhee 
SSttrriinngg 
 IInn ddoouubbllee--qquuootteedd ssttrriinnggss vvaarriiaabbllee vvaalluueess aarree eexxppaannddeedd
your name 
your 
caption 
here 
Conversion / Casting 
 As PHP evaluates eexxpprreessssiioonnss,, aatt ttiimmeess vvaalluueess iinn tthhee 
eexxpprreessssiioonn nneeeedd ttoo bbee ccoonnvveerrtteedd ffrroomm oonnee ttyyppee ttoo aannootthheerr aass 
tthhee ccoommppuuttaattiioonnss aarree ddoonnee.. 
 PPHHPP ddooeess aaggggrreessssiivvee iimmpplliicciitt ttyyppee ccoonnvveerrssiioonn ((ccaassttiinngg)) 
 YYoouu ccaann aallssoo mmaakkee ttyyppee ccoonnvveerrssiioonn ((ccaassttiinngg)) eexxpplliicciitt wwiitthh 
ccaassttiinngg ooppeerraattoorrss..
your name 
your 
caption 
here 
Forms Submit Data 
<p> 
<h2>Enter username and password</h2> 
<form name="input" action="" method="get"> 
Username: <input type="text" name="usr"><br> 
Password: <input type="password" name="pwd"> 
<input type="submit" value="Submit"> 
</form> 
</P>
your name 
your 
caption 
here 
$_GET , $_POST & $_REQUEST 
 PHP loads the values for tthhee UURRLL ppaarraammeetteerrss iinnttoo aann aarrrraayy 
ccaalllleedd $$__GGEETT aanndd tthhee PPOOSSTT ppaarraammeetteerrss iinnttoo aann aarrrraayy ccaalllleedd 
$$__PPOOSSTT 
 TThheerree iiss aannootthheerr aarrrraayy ccaalllleedd $$__RREEQQUUEESSTT wwhhiicchh mmeerrggeess GGEETT 
aanndd PPOOSSTT ddaattaa
your name 
your 
caption 
here 
$_GET and $_POST 
<p> 
<h2>Enter username and password</h2> 
<form name="input" method="get"> 
Username: <input type="text" name="usr" ><br> 
Password: <input type="password" name="pwd"> 
<input type="submit" value="Submit"> 
</form> 
<pre>$_GET: 
<?php 
print_r($_GET); 
?> 
</pre> 
</P>
your name 
your 
caption 
here 
Processing POST Data 
<?php 
$guess = ''''; 
$message = false; 
if ( isset($_POST[''guess'']) ) { 
// Trick for integer / numeric parameters 
$guess = $_POST[''guess''] + 0; 
if ( $guess == 42 ) { 
$message = "Great job!"; 
} else if ( $guess < 42 ) { 
$message = "Too low"; 
} else { 
$message = "Too high..."; 
} 
} 
?>
your name 
your 
caption 
here 
Processing POST Data 
<html> 
<head> 
<title>A Guessing game</title> 
</head> 
<body style="font­­family: 
sans­­serif;"> 
<p>Guessing game...</p> 
<?php 
if ( $message !== false ) { 
echo("<p>$message</p>n"); 
} 
?> 
<form method="post"> 
<p><label for="guess">Input Guess</label> 
<input type="text" name="guess" id="guess" size="40">
your name 
your 
caption 
here 
Processing POST Data 
<?php echo 'value="' . htmlentities($guess) . ''"''; 
?> 
/></p> 
<input type="submit"/> 
</form> 
</body>
your name 
your 
caption 
here 
Other Input Types 
 TTeexxtt 
 PPaasssswwoorrdd 
 RRaaddiioo BBuuttttoonn 
 CChheecckk BBooxx 
 SSeelleecctt // DDrroopp--DDoowwnn 
 TTeexxttAArreeaa 
 CCoolloorr 
 DDaattee 
 EEmmaaiill 
 NNuummbbeerr 
 UUrrll
your name 
your 
caption 
here 
Introduction to MySQL
your name 
your 
caption 
here 
Relational ddaattaabbaasseess 
RReellaattiioonnaall ddaattaabbaasseess mmooddeell ddaattaa bbyy ssttoorriinngg rroowwss 
aanndd ccoolluummnnss iinn ttaabblleess.. TThhee ppoowweerr ooff tthhee rreellaattiioonnaall 
ddaattaabbaassee lliieess iinn iittss aabbiilliittyy ttoo eeffffiicciieennttllyy rreettrriieevvee ddaattaa 
ffrroomm tthhoossee ttaabblleess aanndd iinn ppaarrttiiccuullaarr wwhheerree tthheerree aarree 
mmuullttiippllee ttaabblleess aanndd tthhee rreellaattiioonnsshhiippss bbeettwweeeenn tthhoossee 
ttaabblleess iinnvvoollvveedd iinn tthhee qquueerryy..
your name 
your 
caption 
here 
Terminology 
DDaattaabbaassee -- CCoonnttaaiinnss mmaannyy ttaabblleess 
AAttttrriibbuuttee ((aallssoo ccoolluummnn oorr ffiieelldd)) -- OOnnee ooff ppoossssiibbllyy mmaannyy eelleemmeennttss ooff 
ddaattaa ccoorrrreessppoonnddiinngg ttoo tthhee oobbjjeecctt rreepprreesseenntteedd bbyy tthhee rrooww 
RReellaattiioonn ((oorr ttaabbllee)) -- CCoonnttaaiinnss ttuupplleess aanndd aattttrriibbuutteess 
TTuuppllee ((oorr rrooww)) -- IIss aa sseett ooff ffiieellddss iitt ggeenneerraallllyy rreepprreesseennttss aann ““oobbjjeecctt”” 
lliikkee aa ppeerrssoonn oorr aa mmuussiicc ttrraacckk
your name 
your 
caption 
here 
SQL 
Structured QQuueerryy LLaanngguuaaggee iiss tthhee llaanngguuaaggee wwee uussee ttoo iissssuuee 
ccoommmmaannddss ttoo tthhee ddaattaabbaassee 
 CCrreeaattee aa ttaabbllee 
 RReettrriieevvee ssoommee ddaattaa 
 IInnsseerrtt ddaattaa 
 DDeelleettee ddaattaa
your name 
your 
caption 
here 
MySQL 
MySQL is a popular choice of database ffoorr uussee iinn wweebb 
aapppplliiccaattiioonnss,, aanndd iiss aa cceennttrraall ccoommppoonneenntt ooff tthhee wwiiddeellyy uusseedd 
LLAAMMPP ooppeenn ssoouurrccee wweebb aapppplliiccaattiioonn ssooffttwwaarree ssttaacckk ((aanndd ootthheerr 
''AAMMPP'' ssttaacckkss)).. FFrreeee--ssooffttwwaarree--ooppeenn ssoouurrccee pprroojjeeccttss tthhaatt rreeqquuiirree aa 
ffuullll--ffeeaattuurreedd ddaattaabbaassee mmaannaaggeemmeenntt ssyysstteemm oofftteenn uussee MMyySSQQLL..
your name 
your 
caption 
here 
Communicating with MySQL 
We need some kind of interface ssoo wwee ccaann ttyyppee SSQQLL ccoommmmaannddss 
 CCoommmmaanndd lliinnee 
 FFuullll SSccrreeeenn
your name 
your 
caption 
here 
Application Structure
your name 
your 
caption 
here 
GUI- PhpMyadmin
your name 
your 
caption 
here 
MySQL Commands 
 SShhooww ddaattaabbaasseess 
 CCrreeaattiinngg aa ddaattaabbaassee 
 CCrreeaattiinngg aa ttaabbllee 
 DDeessccrriibbee ttaabbllee
your name 
your 
caption 
here 
MySQL Commands 
CCrreeaattiinngg aa DDaattaabbaassee 
 CREATE DATABASE stddatabase; 
 GRANT ALL ON stddatabase.* TO root@localhost 
IDENTIFIED BY ''admin''; 
 USE stddatabase;
your name 
your 
caption 
here 
CCrreeaattiinngg aa TTaabbllee 
create table usrinfo( 
fname varchar(32) not null, 
lname varchar(32), 
uname varchar(32) not null, 
pwd varchar(32) not null, 
sex varchar(6) not null, 
deg varchar(6) not null, 
bname int, 
iname int, 
about varchar(300), 
tech varchar(10), 
color varchar(10), 
bday date, 
email varchar(32), 
mno int, 
url varchar(32), 
primary key (uname) 
);
your name 
your 
caption 
here 
Describe Table 
Describe usrinfo;
your name 
your 
caption 
here 
Inserting into Table 
INSERT INTO USRINFO(fname, lname, uname, pwd, 
sex, deg, bname, iname, about, tech, color, 
bday, mno, url) 
VALUES(''ramesh'',''wadawadagi'',''rswbec'',''admin'' 
,''male'',''mtech'',1,3,''i love to work on php 
and 
mysql'',''html'',''#0000ff'',09/02/2000,''809507054 
8'',''rswlib.co.in'');
your name 
your 
caption 
here 
Inserting into Table 
INSERT INTO USRINFO(fname, lname, uname, pwd, sex, deg, 
bname, iname, about, tech, color, bday, mno, url) 
VALUES(''ramesh'',''wadawadagi'',''rswbec'',''admin'',''male'',''mtech'', 
1,3,''i love to work on php and 
mysql'',''html'',''#0000ff'',09/02/2000,''8095070548'',''rswlib.co.in 
''); 
FFeettcchhiinngg ffrroomm tthhee TTaabbllee 
SELECT * FROM usrinfo;
your name 
your 
caption 
here 
Accessing MySQL Using PDO 
Multiple Ways ttoo AAcccceessss MMyySSqqll 
PPHHPP iiss eevvoollvviinngg -- tthheerree aarree tthhrreeee wwaayyss ttoo aacccceessss 
MMyySSqqll ffrroomm PPHHPP 
 LLeeggaaccyy nnoonn--OOOO mmyyssqqll__ rroouuttiinneess ((ddeepprreeccaatteedd)) 
 NNeeww mmyyssqqllii ((OOOO vveerrssiioonn tthhaatt iiss ssiimmiillaarr ttoo mmyyssqqll__)) 
 PPDDOO -- PPoorrttaabbllee DDaattaa OObbjjeeccttss
your name 
your 
caption 
here 
Accessing MySQL Using different ways
your name 
your 
caption 
here 
Application Structure
your name 
your 
caption 
here 
Database Connection
your name 
your 
caption 
here 
Database Connection using PDO 
The PHP Data Objects (PDO) extension defines a lightweight, consistent 
interface for accessing databases in PHP. 
 PDO::exec —— Execute an SQL statement and return the number of affected 
rows 
 PDO::prepare —— Prepares a statement for execution and returns a 
statement object 
 PDO::query —— Executes an SQL statement, returning a result set as a 
PDOStatement object 
 PDOStatement::execute —— Executes a prepared statement 
 PDOStatement::fetch —— Fetches the next row from a result set 
 PDOStatement::fetchAll —— Returns an array containing all of the result 
set rows
your name 
your 
caption 
here 
Database Connection 
<?php 
try { 
$db = new PDO(''mysql:host=localhost;port=8889;dbname=usrdatabase'',''root'', 
''admin''); 
echo "PDO connection object created"; 
} 
catch(PDOException $e) 
{ 
echo $e­­> 
getMessage(); 
} 
?>
your name 
your 
caption 
here 
Insert Query 
<?php 
Try { 
$db = new 
PDO(''mysql:host=localhost;port=8889;dbname=registration'',''root'',''admin''); 
if (isset($_POST[''fname'']) 
&& isset($_POST[''lname'']) 
. 
. 
&& isset($_POST[''about''])) 
{ 
$sql = "INSERT INTO usrinfo (fname,...,about) VALUES (:fname, ..., :about)"; 
$stmt = $db­­> 
prepare($sql); 
$stmt­­> 
execute(array('':fname'' => $_POST[''fname''], 
. 
. 
'':about'' => $_POST[''about''], 
)); 
} 
} catch(PDOException $e) 
{ echo $e­­> 
getMessage(); } 
?>
your name 
your 
caption 
here 
Select Query 
<?php 
echo "<pre>n"; 
$pdo=new PDO(''mysql:host=localhost;port=8889;dbname=usrdatabase'',''root'', 
''admin''); 
$stmt = $pdo­­> 
query("SELECT * FROM usrinfo"); 
while ( $row = $stmt­­> 
fetch(PDO::FETCH_ASSOC) ) { 
print_r($row); 
} 
echo "</pre>n"; 
?>
your name 
your 
caption 
here 
Select Query 
Array 
( 
[fname] => ramesh 
[lname] => wadawadagi 
[uname] => rswbec 
[pwd] => admin 
[sex] => male 
[deg] => mtech 
[bname] => mtech 
[iname] => bec,bagalkot 
[about] => i love building apps in php and mysql 
[tech] => html 
[color] => #0000ff 
[bday] => 1981­­06­­19 
[email] => rswbec@gmail 
[mno] => 2147483647 
[url] => rswlib.co.in 
)
your name 
your 
caption 
here 
Delete Query 
<?php 
$a=$_GET[''action'']; 
$db = new 
PDO(''mysql:host=localhost;port=8889;dbname=registration'',''root'',''admin''); 
$sql="DELETE FROM usrinfo WHERE uname = :uname"; 
$query = $db­­> 
prepare($sql); 
$query­­> 
execute(array('':uname'' => $a)); 
?>
your name 
your 
caption 
here 
Any queries...?
your name 
your 
caption 
here 
Thank you....

More Related Content

Similar to Php mysql

introduccion basica php
introduccion basica phpintroduccion basica php
introduccion basica phpPablo Mamani
 
Ataques a bases de datos
Ataques a bases de datosAtaques a bases de datos
Ataques a bases de datoscmarindi
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22Bilal Ahmed
 
[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術Owen Wu
 
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07Bilal Ahmed
 
CheckFood - startup pitch-updated
CheckFood  - startup pitch-updatedCheckFood  - startup pitch-updated
CheckFood - startup pitch-updatedCristian Muraru
 
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjille
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjilleVähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjille
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjilleSeravo
 

Similar to Php mysql (8)

introduccion basica php
introduccion basica phpintroduccion basica php
introduccion basica php
 
Securing PHP Applications
Securing PHP ApplicationsSecuring PHP Applications
Securing PHP Applications
 
Ataques a bases de datos
Ataques a bases de datosAtaques a bases de datos
Ataques a bases de datos
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術
 
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07
 
CheckFood - startup pitch-updated
CheckFood  - startup pitch-updatedCheckFood  - startup pitch-updated
CheckFood - startup pitch-updated
 
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjille
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjilleVähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjille
Vähemmän ja nopeammin – Välimuistivinkit WordPress-kehittäjille
 

Php mysql

  • 1. your name your caption here Web Development using PHP & MySQL R S Wadawadagi Asst. Prof Dept of MCA, BEC, Bagalkot
  • 2. your name your caption here Request / Response Cycle JavaScript HTML GET AJAX HTTP CSS Request Response POST PHP MySqlMVC JSP Cookies
  • 3. your name Open Source Technologies your caption here LLIINNUUXX -- LLiinnuuxx iiss oonnee ooff ppooppuullaarr vveerrssiioonn ooff UUNNIIXX ooppeerraattiinngg SSyysstteemm.. IItt iiss ooppeenn ssoouurrccee aass iittss ssoouurrccee ccooddee iiss ffrreeeellyy aavvaaiillaabbllee.. IItt iiss ffrreeee ttoo uussee.. LLiinnuuxx wwaass ddeessiiggnneedd ccoonnssiiddeerriinngg UUNNIIXX ccoommppaattiibbiilliittyy.. IItt''ss ffuunnccttiioonnaalliittyy lliisstt iiss qquuiittee ssiimmiillaarr ttoo tthhaatt ooff UUNNIIXX.. AAPPAACCHHEE -- TThhee AAppaacchhee HHTTTTPP SSeerrvveerr PPrroojjeecctt iiss aa ccoollllaabboorraattiivvee ssooffttwwaarree ddeevveellooppmmeenntt eeffffoorrtt aaiimmeedd aatt ccrreeaattiinngg aa rroobbuusstt,, ccoommmmeerrcciiaall--ggrraaddee,, ffeeaattuurreeffuull,, aanndd ffrreeeellyy--aavvaaiillaabbllee ssoouurrccee ccooddee iimmpplleemmeennttaattiioonn ooff aann HHTTTTPP ((WWeebb)) sseerrvveerr.. MMYYSSQQLL -- MMyySSQQLL iiss oonnee ooff tthhee mmoosstt ppooppuullaarr ffrreeee aanndd ooppeenn ssoouurrccee ddaattaabbaassee eennggiinneess iinn tthhee mmaarrkkeett ppllaaccee.. MMyySSQQLL ppoowweerrss FFaacceebbooookk,, YYaahhoooo!!,, WWoorrddPPrreessss,, DDrruuppaall,, JJoooommllaa,, aanndd mmiilllliioonnss ooff ootthheerr ddyynnaammiicc wweebb ssiitteess.. PPHHPP -- PPHHPP iiss tthhee mmoosstt wwiiddeellyy uusseedd ssccrriippttiinngg llaanngguuaaggee ffoorr wweebb pprrooggrraammmmiinngg.. PPHHPP eexxtteennddss HHTTMMLL ppaaggeess bbyy aaddddiinngg sseerrvveerr--eexxeeccuutteedd ccooddee sseeggmmeennttss ttoo HHTTMMLL ppaaggeess.. TThhee oouuttppuutt ooff tthhee eexxeeccuuttiioonn ooff tthhee PPHHPP ccooddee iiss mmeerrggeedd iinnttoo tthhee HHTTMMLL ppaaggee..
  • 4. your name your caption here Setting up a Development Server What we need.....? 1) Apache Web Server (Includes PHP) 2) MySql Database Server 3) MySql Administation Software (PhpMyAdmin) We could install all this by hand... All-In-One Pre-Packaged LAMP - Linux, Apache, MySQL, and PHP Prefer: MAMP on Macintosh XAMPP on Windows
  • 5. your name your caption here Programmer Editor Do not use Word, TextEdit, or NotePad  Programmer Editor  Linux: Gedit, Bluefish, Geany  Windows: NotePad++  Macintosh: TextWrangler  Feel free to use an Integrated Development Environment such Eclipse, etc. if you have experience.
  • 6. your name your caption here The History of PHP  PPHHPP-- PPHHPP HHyyppeerrtteexxtt PPrreepprroocceessssoorr  RRaassmmuuss LLeerrddoorrff ((11999944))  NNoott aa ttrraaiinneedd ccoommppuutteerr sscciieennttiisstt  CCoonnssuullttaanntt bbuuiillddiinngg ddyynnaammiicc wweebb ssiitteess -- ggoott ttiirreedd ooff ddooiinngg tthhee ssaammee tthhiinngg oovveerr aanndd oovveerr iinn CC  RReeuussaabbllee bbiittss ++ HHTTMMLL TTeemmppllaatteess
  • 7. your name your caption here Introduction to PHP  SSyynnttaaxx iiss iinnssppiirreedd bbyy CC && ppeerrll  CCuurrllyy bbrraacceess,, sseemmiiccoolloonnss,, nnoo ssiiggnnffiiccaanntt wwhhiitteessppaaccee  DDoollllaarr ssiiggnnss ttoo ssttaarrtt vvaarriiaabbllee nnaammeess,, aassssoocciiaattiivvee aarrrraayyss  EExxtteennddss HHTTMMLL ttoo aadddd sseeggmmeennttss ooff PPHHPP wwiitthhiinn aann HHTTMMLL ffiillee  PPHHPP ffiillee rruunnss oonn wweebb sseerrvveerr,, iinnppuuttss PPHHPP ccooddee,, ccoommppiilleess ttoo bbyytteeccooddee,, oouuttppuuttss WWeebb PPaaggeess..  CCrreeaatteess DDyynnaammiicc WWeebb PPaaggeess,, uussiinngg SSeerrvveerr SSiiddee SSccrriippttiinngg.. ((lliikkee ..aasspp,, ..jjsspp,, ppeerrll)).. CClliieennttss ““RRuunn”” tthheessee wweebb ppaaggeess wwhheenn vviissiitteedd..
  • 8. your name your caption here Features of PHP  HHTTTTPP aauutthheennttiiccaattiioonn wwiitthh PPHHPP  CCooookkiieess  SSeessssiioonnss  DDeeaalliinngg wwiitthh XXFFoorrmmss  HHaannddlliinngg ffiillee uuppllooaaddss  UUssiinngg rreemmoottee ffiilleess  CCoonnnneeccttiioonn hhaannddlliinngg  PPeerrssiisstteenntt DDaattaabbaassee CCoonnnneeccttiioonnss  SSaaffee MMooddee  CCoommmmaanndd lliinnee uussaaggee —— UUssiinngg PPHHPP ffrroomm tthhee ccoommmmaanndd lliinnee  GGaarrbbaaggee CCoolllleeccttiioonn  DDTTrraaccee DDyynnaammiicc TTrraacciinngg
  • 9. your name your caption here <!DOCTYPE html> <html> <body> <h1> Hello from BECBGK''s home Page </h1> <p> <?php echo "<h2>","My first PHP script...!","</h2>"; $sum = 30 + 40; echo "<h2>","The sum of 30 and 40 is $sum","</h2>"; ?> </p> </body> </html> My First PHP Script
  • 10. your name your caption here <!DOCTYPE html> <html> <body> <h1>Hello from BECBGK''s home Page</h1> <p> <?php echo "<h2>","My first PHP script...!","</h2>"; $sum = 30 + 40; echo "<h2>","The sum of 30 and 40 is $sum","</h2>"; ?> </p> </body> </html> My First PHP Script
  • 11. your name your caption here PHP From the Command Line  You ccaann rruunn PPHHPP ffrroomm tthhee ccoommmmaanndd lliinnee -- tthhee oouuttppuutt ssiimmppllyy ccoommeess oouutt oonn tthhee tteerrmmiinnaall  IItt ddooeess nnoott hhaavvee ttoo bbee ppaarrtt ooff aa rreeqquueesstt--rreessppoonnssee ccyyccllee <?php echo("Hello World!"); echo("n"); ?>
  • 12. your name Keywords your caption here aabbssttrraacctt aanndd aarrrraayy(()) aass bbrreeaakk ccaassee ccaattcchh ccllaassss cclloonnee ccoonnsstt ccoonnttiinnuuee ddeeccllaarree ddeeffaauulltt ddoo eellssee eellsseeiiff eenndd ddeeccllaarree eennddffoorr eennddffoorreeaacchh eennddiiff eennddsswwiittcchh eennddwwhhiillee eexxtteennddss ffiinnaall ffoorr ffoorreeaacchh ffuunnccttiioonn gglloobbaall ggoottoo iiff iimmpplleemmeennttss iinntteerrffaaccee iinnssttaanncceeooff nnaammeessppaaccee nneeww oorr pprriivvaattee pprrootteecctteedd ppuubblliicc ssttaattiicc sswwiittcchh $$tthhiiss tthhrrooww ttrryy uussee vvaarr wwhhiillee xxoorr
  • 13. your name Variable Names your caption here  Start with a dollar sign ($) ffoolllloowweedd bbyy aa lleetttteerr oorr uunnddeerrssccoorree,, ffoolllloowweedd bbyy aannyy nnuummbbeerr ooff lleetttteerrss,, nnuummbbeerrss,, oorr uunnddeerrssccoorreess  CCaassee mmaatttteerrss $$aabbcc == 1122;; $$ttoottaall == 00;; $$llaarrggeesstt__ssoo__ffaarr == 00;; aabbcc == 1122;; $$22pphhpp == 00;; $$bbaadd--ppuunncc == 00;;
  • 14. your name Expressions your caption here  Completely nnoorrmmaall lliikkee ootthheerr llaanngguuaaggeess (( ++ -- // ** ))  MMoorree aaggrreessssiivvee iimmpplliicciitt ttyyppee ccoonnvveerrssiioonn <<??pphhpp $$xx == ""1155"" ++ 2277;; eecchhoo(($$xx));; 4422 eecchhoo((""nn""));; ??>>
  • 15. your name Operators of Note your caption here  IInnccrreemmeenntt // DDeeccrreemmeenntt (( ++++ ---- ))  SSttrriinngg ccoonnccaatteennaattiioonn (( .. ))  EEqquuaalliittyy (( ==== !!== ))  IIddeennttiittccaall (( ====== !!==== ))  TTeerrnnaarryy (( ?? : ))  SSiiddee--eeffffeecctt AAssssiiggnnmmeenntt (( ++== --== ..== eettcc..))  SSttrriinngg ooppeerraattoorrss (( ..,, ..==))  AArrrraayy ooppeerraattoorrss(( TToo ccoommppaarree ttwwoo aarrrraayyss))  IIggnnoorree tthhee rraarreellyy--uusseedd bbiittwwiissee ooppeerraattoorrss (( >>>> <<<< ^^ || && ))
  • 16. your name your caption here Output statements  ““eecchhoo”” iiss aa llaanngguuaaggee ccoonnssttrruucctt -- ccaann bbee ttrreeaatteedd lliikkee aa ffuunnccttiioonn wwiitthh oonnee ppaarraammeetteerr.. WWiitthhoouutt ppaarreenntthheessiiss,, iitt aacccceeppttss mmuullttiippllee PPaarraammeetteerrss.. ““pprriinntt”” iiss aa ffuunnccttiioonn -- oonnllyy oonnee ppaarraammeetteerr bbuutt ppaarreenntthheessiiss aarree ooppttiioonnaall ssoo iitt ccaann llooookk lliikkee aa llaanngguuaaggee ccoonnssttrruucctt <?php $x = "15" + 27; echo $x; echo("n"); echo $x, "n"; print $x; print "n"; print($x); print("n"); ?> lab2.php
  • 17. your name your caption here Conditional - if  Logical operators ( == != << >> <<== >>== aanndd oorr !! ))  CCuurrllyy bbrraacceess <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!n"; Hello world! } else { print "Wrong answern"; } ?>
  • 18. your name your caption here Branching & bounding  iiff ssttaatteemmeenntt -- eexxeeccuutteess ssoommee ccooddee oonnllyy iiff aa ssppeecciiffiieedd ccoonnddiittiioonn iiss ttrruuee  iiff......eellssee ssttaatteemmeenntt -- eexxeeccuutteess ssoommee ccooddee iiff aa ccoonnddiittiioonn iiss ttrruuee aanndd aannootthheerr ccooddee iiff tthhee ccoonnddiittiioonn iiss ffaallssee  iiff......eellsseeiiff........eellssee ssttaatteemmeenntt -- sseelleeccttss oonnee ooff sseevveerraall bblloocckkss ooff ccooddee ttoo bbee eexxeeccuutteedd  sswwiittcchh ssttaatteemmeenntt -- sseelleeccttss oonnee ooff mmaannyy bblloocckkss ooff ccooddee ttoo bbee eexxeeccuutteedd
  • 19. your name your caption here Associative Arrays  Py Like Pytthhoonn DDiiccttoonnaarriieess++LLiissttss -- bbuutt mmoorree ppoowweerrffuull CCaann bbee kkeeyy ==>> vvaalluuee oorr ssiimmppllyy iinnddeexxeedd bbyy nnuummbbeerrss  IIggnnoorree ttwwoo--ddiimmeennssiioonnaall aarrrraayyss ffoorr nnooww......
  • 20. your name your caption here Integer Indices <?php $stuff = array("Hi", "There"); echo $stuff[0], "n"; echo $stuff[1], "n"; ?> Hi There
  • 21. your name your caption here Integer Indices <?php $stuff = Array(); $stuff[] = "Hello"; $stuff[] = "World"; echo $stuff[1], "n"; ?> World
  • 22. your name your caption here Key / Value <?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); echo "Peter is " . $age[''Peter''] . " years old."; ?>
  • 23. your name your caption here Dumping an Array  The function print_r() dduummppss oouutt PPHHPP ddaattaa -- iitt iiss uusseedd mmoossttllyy ffoorr ddeebbuuggggiinngg <<??pphhpp $$ssttuuffff == aarrrraayy((""nnaammee"" ==>> ""XXYYZZ"",,""ccoouurrssee"" ==>> ""MMCCAA""));; pprriinntt__rr(($$ssttuuffff));; ??>>
  • 24. your name your caption here Looping  while ­­loops through a block of code as long as the specified condition is true  do...while ­­loops through a block of code once, and then repeats the loop as long as the specified condition is true  for ­­loops through a block of code a specified number of times  foreach ­­loops through a block of code for each element in an array
  • 25. your name your caption here Looping Through an associative array <?php $stuff = array("name" => "XYZ","course" => "MCA"); foreach($stuff as $k => $v ) { echo "Key=",$k," Val=",$v,"n"; } ?> KKeeyy==nnaammee VVaall==XXYYZZ KKeeyy==ccoouurrssee VVaall==MMCCAA
  • 26. your name your caption here Strings  String literals ccaann uussee ssiinnggllee qquuootteess oorr ddoouubbllee qquuootteess  TThhee bbaacckkssllaasshh (()) iiss uusseedd aass aann ""eessccaappee"" cchhaarraacctteerr  SSttrriinnggss ccaann ssppaann mmuullttiippllee lliinneess -- tthhee nneewwlliinnee iiss ppaarrtt ooff tthhee SSttrriinngg  IInn ddoouubbllee--qquuootteedd ssttrriinnggss vvaarriiaabbllee vvaalluueess aarree eexxppaannddeedd
  • 27. your name your caption here Conversion / Casting  As PHP evaluates eexxpprreessssiioonnss,, aatt ttiimmeess vvaalluueess iinn tthhee eexxpprreessssiioonn nneeeedd ttoo bbee ccoonnvveerrtteedd ffrroomm oonnee ttyyppee ttoo aannootthheerr aass tthhee ccoommppuuttaattiioonnss aarree ddoonnee..  PPHHPP ddooeess aaggggrreessssiivvee iimmpplliicciitt ttyyppee ccoonnvveerrssiioonn ((ccaassttiinngg))  YYoouu ccaann aallssoo mmaakkee ttyyppee ccoonnvveerrssiioonn ((ccaassttiinngg)) eexxpplliicciitt wwiitthh ccaassttiinngg ooppeerraattoorrss..
  • 28. your name your caption here Forms Submit Data <p> <h2>Enter username and password</h2> <form name="input" action="" method="get"> Username: <input type="text" name="usr"><br> Password: <input type="password" name="pwd"> <input type="submit" value="Submit"> </form> </P>
  • 29. your name your caption here $_GET , $_POST & $_REQUEST  PHP loads the values for tthhee UURRLL ppaarraammeetteerrss iinnttoo aann aarrrraayy ccaalllleedd $$__GGEETT aanndd tthhee PPOOSSTT ppaarraammeetteerrss iinnttoo aann aarrrraayy ccaalllleedd $$__PPOOSSTT  TThheerree iiss aannootthheerr aarrrraayy ccaalllleedd $$__RREEQQUUEESSTT wwhhiicchh mmeerrggeess GGEETT aanndd PPOOSSTT ddaattaa
  • 30. your name your caption here $_GET and $_POST <p> <h2>Enter username and password</h2> <form name="input" method="get"> Username: <input type="text" name="usr" ><br> Password: <input type="password" name="pwd"> <input type="submit" value="Submit"> </form> <pre>$_GET: <?php print_r($_GET); ?> </pre> </P>
  • 31. your name your caption here Processing POST Data <?php $guess = ''''; $message = false; if ( isset($_POST[''guess'']) ) { // Trick for integer / numeric parameters $guess = $_POST[''guess''] + 0; if ( $guess == 42 ) { $message = "Great job!"; } else if ( $guess < 42 ) { $message = "Too low"; } else { $message = "Too high..."; } } ?>
  • 32. your name your caption here Processing POST Data <html> <head> <title>A Guessing game</title> </head> <body style="font­­family: sans­­serif;"> <p>Guessing game...</p> <?php if ( $message !== false ) { echo("<p>$message</p>n"); } ?> <form method="post"> <p><label for="guess">Input Guess</label> <input type="text" name="guess" id="guess" size="40">
  • 33. your name your caption here Processing POST Data <?php echo 'value="' . htmlentities($guess) . ''"''; ?> /></p> <input type="submit"/> </form> </body>
  • 34. your name your caption here Other Input Types  TTeexxtt  PPaasssswwoorrdd  RRaaddiioo BBuuttttoonn  CChheecckk BBooxx  SSeelleecctt // DDrroopp--DDoowwnn  TTeexxttAArreeaa  CCoolloorr  DDaattee  EEmmaaiill  NNuummbbeerr  UUrrll
  • 35. your name your caption here Introduction to MySQL
  • 36. your name your caption here Relational ddaattaabbaasseess RReellaattiioonnaall ddaattaabbaasseess mmooddeell ddaattaa bbyy ssttoorriinngg rroowwss aanndd ccoolluummnnss iinn ttaabblleess.. TThhee ppoowweerr ooff tthhee rreellaattiioonnaall ddaattaabbaassee lliieess iinn iittss aabbiilliittyy ttoo eeffffiicciieennttllyy rreettrriieevvee ddaattaa ffrroomm tthhoossee ttaabblleess aanndd iinn ppaarrttiiccuullaarr wwhheerree tthheerree aarree mmuullttiippllee ttaabblleess aanndd tthhee rreellaattiioonnsshhiippss bbeettwweeeenn tthhoossee ttaabblleess iinnvvoollvveedd iinn tthhee qquueerryy..
  • 37. your name your caption here Terminology DDaattaabbaassee -- CCoonnttaaiinnss mmaannyy ttaabblleess AAttttrriibbuuttee ((aallssoo ccoolluummnn oorr ffiieelldd)) -- OOnnee ooff ppoossssiibbllyy mmaannyy eelleemmeennttss ooff ddaattaa ccoorrrreessppoonnddiinngg ttoo tthhee oobbjjeecctt rreepprreesseenntteedd bbyy tthhee rrooww RReellaattiioonn ((oorr ttaabbllee)) -- CCoonnttaaiinnss ttuupplleess aanndd aattttrriibbuutteess TTuuppllee ((oorr rrooww)) -- IIss aa sseett ooff ffiieellddss iitt ggeenneerraallllyy rreepprreesseennttss aann ““oobbjjeecctt”” lliikkee aa ppeerrssoonn oorr aa mmuussiicc ttrraacckk
  • 38. your name your caption here SQL Structured QQuueerryy LLaanngguuaaggee iiss tthhee llaanngguuaaggee wwee uussee ttoo iissssuuee ccoommmmaannddss ttoo tthhee ddaattaabbaassee  CCrreeaattee aa ttaabbllee  RReettrriieevvee ssoommee ddaattaa  IInnsseerrtt ddaattaa  DDeelleettee ddaattaa
  • 39. your name your caption here MySQL MySQL is a popular choice of database ffoorr uussee iinn wweebb aapppplliiccaattiioonnss,, aanndd iiss aa cceennttrraall ccoommppoonneenntt ooff tthhee wwiiddeellyy uusseedd LLAAMMPP ooppeenn ssoouurrccee wweebb aapppplliiccaattiioonn ssooffttwwaarree ssttaacckk ((aanndd ootthheerr ''AAMMPP'' ssttaacckkss)).. FFrreeee--ssooffttwwaarree--ooppeenn ssoouurrccee pprroojjeeccttss tthhaatt rreeqquuiirree aa ffuullll--ffeeaattuurreedd ddaattaabbaassee mmaannaaggeemmeenntt ssyysstteemm oofftteenn uussee MMyySSQQLL..
  • 40. your name your caption here Communicating with MySQL We need some kind of interface ssoo wwee ccaann ttyyppee SSQQLL ccoommmmaannddss  CCoommmmaanndd lliinnee  FFuullll SSccrreeeenn
  • 41. your name your caption here Application Structure
  • 42. your name your caption here GUI- PhpMyadmin
  • 43. your name your caption here MySQL Commands  SShhooww ddaattaabbaasseess  CCrreeaattiinngg aa ddaattaabbaassee  CCrreeaattiinngg aa ttaabbllee  DDeessccrriibbee ttaabbllee
  • 44. your name your caption here MySQL Commands CCrreeaattiinngg aa DDaattaabbaassee  CREATE DATABASE stddatabase;  GRANT ALL ON stddatabase.* TO root@localhost IDENTIFIED BY ''admin'';  USE stddatabase;
  • 45. your name your caption here CCrreeaattiinngg aa TTaabbllee create table usrinfo( fname varchar(32) not null, lname varchar(32), uname varchar(32) not null, pwd varchar(32) not null, sex varchar(6) not null, deg varchar(6) not null, bname int, iname int, about varchar(300), tech varchar(10), color varchar(10), bday date, email varchar(32), mno int, url varchar(32), primary key (uname) );
  • 46. your name your caption here Describe Table Describe usrinfo;
  • 47. your name your caption here Inserting into Table INSERT INTO USRINFO(fname, lname, uname, pwd, sex, deg, bname, iname, about, tech, color, bday, mno, url) VALUES(''ramesh'',''wadawadagi'',''rswbec'',''admin'' ,''male'',''mtech'',1,3,''i love to work on php and mysql'',''html'',''#0000ff'',09/02/2000,''809507054 8'',''rswlib.co.in'');
  • 48. your name your caption here Inserting into Table INSERT INTO USRINFO(fname, lname, uname, pwd, sex, deg, bname, iname, about, tech, color, bday, mno, url) VALUES(''ramesh'',''wadawadagi'',''rswbec'',''admin'',''male'',''mtech'', 1,3,''i love to work on php and mysql'',''html'',''#0000ff'',09/02/2000,''8095070548'',''rswlib.co.in ''); FFeettcchhiinngg ffrroomm tthhee TTaabbllee SELECT * FROM usrinfo;
  • 49. your name your caption here Accessing MySQL Using PDO Multiple Ways ttoo AAcccceessss MMyySSqqll PPHHPP iiss eevvoollvviinngg -- tthheerree aarree tthhrreeee wwaayyss ttoo aacccceessss MMyySSqqll ffrroomm PPHHPP  LLeeggaaccyy nnoonn--OOOO mmyyssqqll__ rroouuttiinneess ((ddeepprreeccaatteedd))  NNeeww mmyyssqqllii ((OOOO vveerrssiioonn tthhaatt iiss ssiimmiillaarr ttoo mmyyssqqll__))  PPDDOO -- PPoorrttaabbllee DDaattaa OObbjjeeccttss
  • 50. your name your caption here Accessing MySQL Using different ways
  • 51. your name your caption here Application Structure
  • 52. your name your caption here Database Connection
  • 53. your name your caption here Database Connection using PDO The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP.  PDO::exec —— Execute an SQL statement and return the number of affected rows  PDO::prepare —— Prepares a statement for execution and returns a statement object  PDO::query —— Executes an SQL statement, returning a result set as a PDOStatement object  PDOStatement::execute —— Executes a prepared statement  PDOStatement::fetch —— Fetches the next row from a result set  PDOStatement::fetchAll —— Returns an array containing all of the result set rows
  • 54. your name your caption here Database Connection <?php try { $db = new PDO(''mysql:host=localhost;port=8889;dbname=usrdatabase'',''root'', ''admin''); echo "PDO connection object created"; } catch(PDOException $e) { echo $e­­> getMessage(); } ?>
  • 55. your name your caption here Insert Query <?php Try { $db = new PDO(''mysql:host=localhost;port=8889;dbname=registration'',''root'',''admin''); if (isset($_POST[''fname'']) && isset($_POST[''lname'']) . . && isset($_POST[''about''])) { $sql = "INSERT INTO usrinfo (fname,...,about) VALUES (:fname, ..., :about)"; $stmt = $db­­> prepare($sql); $stmt­­> execute(array('':fname'' => $_POST[''fname''], . . '':about'' => $_POST[''about''], )); } } catch(PDOException $e) { echo $e­­> getMessage(); } ?>
  • 56. your name your caption here Select Query <?php echo "<pre>n"; $pdo=new PDO(''mysql:host=localhost;port=8889;dbname=usrdatabase'',''root'', ''admin''); $stmt = $pdo­­> query("SELECT * FROM usrinfo"); while ( $row = $stmt­­> fetch(PDO::FETCH_ASSOC) ) { print_r($row); } echo "</pre>n"; ?>
  • 57. your name your caption here Select Query Array ( [fname] => ramesh [lname] => wadawadagi [uname] => rswbec [pwd] => admin [sex] => male [deg] => mtech [bname] => mtech [iname] => bec,bagalkot [about] => i love building apps in php and mysql [tech] => html [color] => #0000ff [bday] => 1981­­06­­19 [email] => rswbec@gmail [mno] => 2147483647 [url] => rswlib.co.in )
  • 58. your name your caption here Delete Query <?php $a=$_GET[''action'']; $db = new PDO(''mysql:host=localhost;port=8889;dbname=registration'',''root'',''admin''); $sql="DELETE FROM usrinfo WHERE uname = :uname"; $query = $db­­> prepare($sql); $query­­> execute(array('':uname'' => $a)); ?>
  • 59. your name your caption here Any queries...?
  • 60. your name your caption here Thank you....