Sobasicallywhathappensisthe P A P codeparsesandcreates a mysequelstatementandthatfull, mysequelstatementissenttothemysequeldatabaseserverinmysecretdatabaseserver, thenreadsitandthenprocessisbasicallywhateversequelthatwehavepresentedtoitnow.
Whatwe'retalkingaboutistheendusersomehowisabletoinjectthesequelstatementsintowhatissupposedtobejust a normal, innocuoustransactionwiththeserver, andthen, bydoingthat, they'reabletospendhavesomecontroloftheservertodoanynumberofthings, andsothat's a problem.
Andsoallthathappensisthevalueisputwhereverthevariable s statedandinthatwholestatementascentandintomysingledatabaseserverhorses, thatwholestatementwhichcouldcausetheproblems.
Sowhatpreparedstatements?
ItwasItwaskindofaninterestingwayofdoing.
Itiswhathappensisyoucreate a templateforthesequelstatement.
Sobasically, youcreated a templateforthesequelstatementandyouyouputintheselittlequestionmarkstosaywhereourvaluesgo.
Theonlythingthat I willtellyou, especiallyifyouarenewtousingPHPandmysequelandallthatkindofstuff, isthatwhenwedodothesepreparedstatements, weadd a coupleoflevelsofcomplexityforbeingabletoinsertrecords.
Sowecreatedollarsign, name, dollarsign, a dollarsign, gender, theseairgoingtoequalthepostvalues.
SopostourdollarsignunderskyareunderscorePoston, thenname a dollarsignonyourpost A dollarsignUnderscorepostgender.
Sowe'vedonethisinotherprojectsatthispoint, thisissimplygrabbingthevalueofthesenamesthatcomefromtheformname a genderwerethenassigningthosevalleyusedtothenewvariables.
We'vecreated a pHbeheresothatwecaninteractwithhiminPHP.
Thenextcodehereisthesamecodewe'veseen 1000 timesofthis 10000.78 yearsin a passwordanddatabase.
Soit's a localhost.
Sothat's just a localhostusernameofBobPassword.
I wantyouto 456 databaseofClass B.
D.
B hasjustshowedyouWe'rethengoingtocreate a connectionlikewenormallydo.
Sodollarsigncommonequals a newmysequelae.
We'regonnapass a servantandwe'regonnapasstheusername.
We'regonnapassPassword, eh?
We'regonnapassthedatabase.
Thereareclosedparentheses, andofcourse, wedosemicolonbecausethisis P H.
Ifyou'regonnabedoingthingslikefiles, files, PDSandthattypeofthingcouldactuallyinsertthat, sobewouldbe a fourblock.
Sothisisgoingbestringendedyourstringname a gender, closeparentheses, ofcourse, andthendosemiColon.
Thenthenextthingthatwehavetodoissowe'vecreated a statementwe'veboundtheparametersforwithstatementshouldbe, andwhatwe'regoingtobedoingiswe'reactuallygonnabeexecuted, right?
Oneofthenicethingswiththisis, let's say, if I wantedtodoPatsyandthen I'm notthinkingaboutitand I sayKleinhereandthen I say, Girl, oneofthenicepartsthatyoucanactuallyseewithusingpreparedstatementIf I dosubmitquery, they'regonnanoticehere, saysaddedPatsyClineGirl.
Butifwe d'ohandwedo a selectallfromstudents, whatyou'llnoticehereis, sinceit's not, it's notaneditor.
Itwas a stringofseven.
Endanger.
Allthathappensis a zerogetsplacedinthatage.
Sotheniceparthereisatleastyouknowthere's a problem.
You'relike, Oh, I'vegottogobackand I'vegottogetthatagewhereagain, like a lotoftimeswithdatabases, ifyoucouldinsertit, thewrongtypeofdatagetsandserve, youcanhave a lotofproblems, soatleastwiththis, you'vegotzero, soyouknowthatthere's anissuethereandyoucangodealwithit, butbasicallythat's allwe'redealing, dealingwithwiththesepreparedstatements.
Andassuch, youhave a lotofoldtimersthatarescreamingatmeforhow I'vebeenshowingyou.
Howdidhewith P, A.
P andmySiegel?
It's notsecurity, youlong.
It's notsecure.
Youneedtodopreparedstatementsagain.
I have a wayofTV.
I have a wayoftea.
Ifyoudon't liketheway I did, youdon't gottawatchyourvideos.
But I teachbasicallytryingtoshowpeoplethesimplestwaytodothingsagain.
A lotoftimes I genuinelystripoutsecurityagain.
I'm nottellingyoutoputsomeofthestuffthat I doin a productionenvironment, but I wantyoutounderstandthatyoucanbuildthingsandthenonceyouknowyoucanbuildsomething, then I wantyoutolearnhowtomakeitbetter, makeitmoresecureandthen a fewstepsdownwine.
Usingpreparestatementsis a singlewaythatyoucantrytomitigatethedamagetowardsyouoryoursequelservers.
Butit's nottheonlything.
Sodon't feellikeoh, I knowpreparedstatements.
Sotherefore, myserverswillbesecure.
Noone, I thinkthatwillstaywiththisisgooutthereanddoyourownresearchforusingthispreparedstatements, especiallyifyou'relookingatusingpreparedstatementsin a productionenvironment.
As I wasdoingresearchforthisclass, itwasinterestingtoseeboththebenefitsofusingpreparedstatementsagainforthoseinjectionattacks, butalsothenseeingsomeofthedownsidesolikewiththedownsidesorusingpreparedstatementsisdependingonthecontextyou'reusingthemin.
Ifyou'vegot a virtualmachineright, yougot a virtualmachine.
Yearsinteractwithvirtualmachine.
Using a couplemorecomputecyclesisn't gonnamatter, butright, ifyou'vegot a productionenvironment, you'vegot 10,000 usershittingyourservereveryhourusingpreparedstatements.
Ifyoudon't necessarilyneedthatuse, a preparedstatementmayincreaseyourserverload.
There's multipledifferentwaysofactuallytryingtocleanupthosevaluesagaintodothingslikepreventsequelinjectionattacksandin a productionenvironment, theremaybeanothermethodofbasicallygettinggettingtheabilitytostripoutpossiblesequelinjectionattacksthatarenotnecessarilythesepreparedstatementsrightagainforyou.
Preparedstatementsareprobablyfive, butit's a typeofthingtoresearchandagaintofigureouthowyou'regonna d'ohthings.
As I say, youknow, there's 20 waystoskin a cat.
Youjusthavetofigureouttheproperway.
Howdo I skincan't inthisparticularsituation?
And I thinkthat's what a lotoftechnologyprofessionalsand a lotofcodersreallydon't thinkabout.
Theydon't thinkaboutthecontext.
I don't thinkaboutthesituation.
Theyjustsay, Thisisright.
ThisiswrongWhen a realityattheendofthedaydependsondependsonwhatyou'redealing.
Soanyways, that's Ah, that's, um, preparedstatementsforyouregrettedstatements, basicallyallowingyoutosendthetemplatefrom a statementandthevaluesforthestatementseparately.
Thishelpspreventsequelinjectionattacks.
Asalways, I enjoydoingthisclassandforthenextone, apparentlythetypeofcontentyoujustsawisnotwhatSusan W.
WantsforthefutureofYouTube.
ThismeansthatrecommendationsbyYouTubetothischannelhavedroppedmassively, andviewsarebecoming a comicallysmall I hatetoask.
I usedtosay I wouldneverask, butifyoucouldsubscribelikecommonandmostimportantly, sharethevideosthatyouappreciate, thatmayhelpslowthedeathofthischannel.