PHP GUIDE BOOK First Edition

Size: px
Start display at page:

Download "PHP GUIDE BOOK First Edition"

Transcription

1

2 PHP GUIDE BOOK First Edition 2 Youth Dreams 2

3 အမ စက မဂ လ ပ ခင ဗ က န Part (I) ပ ဆ ပ တ ႔ ပ ခ ႔တ ႔လက တ စ အ ပ ထ တ ခ ႔ပ တယ ၂၀၁၀ၾသဂ တ ၁၃မ Part (II) ထ တ မယ လ ႔ ပ ခ ႔ပ တယ အ လ မ ဆ စ အ ပ ဖစ ပ ရ ပ နမယ ထ င ပ တယ တက ယ ရ ပ တ ႔အခ မ First edition လ ႔ထ တ တ က ပ ပ သင တ တယ လ ႔ယ ဆ မ ပ တ ယ ဘ ရယ မဟ တ ပ ဘ အ ရ ႕က တစ အ ပ န ႔အမည က အ င ပ Second edition လ လ မ ႔မယ လ ႔ တ ႔မထင ပ ဘ ဒ လ ပ န မည ပ တ ပ ပထမစ အ ပ မ စ မ က ၇၀ ၀န က င န ႔ ထ တ ပ ခ ႔ ပ တ ႔ဒ First Edition မ က န န က ထပ စ မ က ၇၀ န ပ လ က ထပ ပ င ထည လ က ပ တ ယ ဒ စ အ ပ မ တ ႔တ တ င သ မ ပထမစ အ ပ မ အ လ တ ၾက လ ပ လ က လ ႔Chapter တ သ ခ မစ ထ ဖစ တ တ ကအစ ပ စ တ ပန ပင ထ ပ ၾက စ ရ ထ ပ တယ စ တ တ ႔ မ ပ င သ ပ ဘ အဆ င ပ အ င အ ရ ႕အ န က ပန စ စဥ ထ တ တ ႔ရ ပ တ ယ ဒ စ အ ပ က လ႔လ ပ တ ႔အခ သင PHP မတတ သ ပ ဘ Web Developer လည မ ဖစ ပ ဒ ပမယ ႔မဖတ ခင က န ႔ယ ဥ ရင တ ႔သ င အမ ၾက က ခ သ မ ပ PHP န ႔ပတ သ တ ပ အ ခခ က င တ ရ ပ ဆ က လ က လ ႔လ ဖ ႔ လမ ပ င သ မယ လ ႔ယ ၾက ည ပ တယ ဒ စ အ ပ န ႔ လ႔လ ဖ ႔Programming အ ခခ ရ က အလ န က င ပ သည မရ ပ က ဖည ဖည ခ င ဖတ ပ.. code တ င က တ တ င သ မ run ပ လ ႔အၾက ပ ပ ရ စ ၀န ခ ခ င တ တ က တ ႔code တ က w3schools.com က နreference လ ပ ပ သ ထ ပ တ ယ အမ စ က ဘ သ ပန တ ဖစ ပ တ ယ န လည မယ လ ႔ တ ႔ မ လ င မ ပ တယ တ စ စ တစ ရ အဆင မ ပတ ရ ခ ႔ သ က န ည လ ႔သ ဖစ ၾက င ရ နစဥ မ အ ပ ခ ႔သ မ အ လ က က ဇ တင ပ တ ယ အ လ သ ဒ င လ ပ ဆ ၾက သ ဖတ ရ အ ပ လ ႔လ ၾကသ ည အစ က မ င မ မ အ လ က လ ည က ဇ တင ပ တ ယ စက မစပ က န စ ရ ဆရ မဟ တ ပ က ည ခ င တ ႔စ တ သ က သ က န ႔ ရ တ ဖစ ပ တယ န က လည စ တ အမ ၾက ရ ဖ ႔ အစ စဥ မရ ပ ခင ဗ တ တ င သ လ က တ ႔ က ည သ မ ပ အ လ က က ဇ တ င ပ တ ယ အၾက ပ ခ က မ က အ မ သ ႔ ပ ပ ႔ င ပ တ ယ ဘ တ အသ စ ရ နမလ ဆ တ က လ ည က န ႔ဘ လ ႔ မ လ ရ က လ ည ပတ င ၾက င ပ လ႔လ ၾကသ အ လ က လ စ လ က မ မင ရ န 3 Youth Dreams 3

4 Contents at a Glance Chapter 1 Introducing PHP 5 Chpater 2 The Building Blocks of PHP 7 Chapter 3 Flow Control Functoins in PHP 14 Chapter 4 Working With Functions and Forms 25 Chapter 5 PHP Date, Include, File Handling & Some PHP Advaced 32 Chapter 6 PHP and AJAX 54 Chapter 7 PHP MyAdmin Basic 74 Chapter 8 PHP and Database 83 Chapter 9 XML and PHP 97 Chatper 10 Exception Handling and Filter in PHP 124 Conclusion Youth Dreams 4

5 Chapter 1 Introducing PHP What is PHP? PHP ဆ တ dynamic web pages တ အတ က ရည ရ ယ ပ ပၚ ပ က လ ခ ႔တ ႔scripting language ဖစ ပ တယ PHP က web scripts တ ရ ဖ ႔ဖန တ ခ ႔တ သ ဖစ ပ တ ယ stand alone application တ ရ ဖ ႔မဟ တ ပ ဘ (ဒ ပမယ ႔ အခ အခ န မ တ ႔application တ က လ ည PHP န ႔ ရ လ ႔ရ နပ ပ ) PHP က မ လပထ မဆ ဖန တ ခ ႔သ က တ ႔Rasmus Lerdorf ပ ဖစ ပ တယ စစ ပၚခ င 1994 မ PHP ရ ႕အရ ည က Personal Home Page လ ႔Rasmus Lerdorf က ခၚတ င ခ ႔ပ တ ယ. န က ပ င မ တ ႔အခ သ ၾက တ ႔အတ င PHP: Hypertext Preprocessor ဖစ ပ တ ယ PHP ဟ ယ န႔အခ မ တ ႔အသ အမ ဆ programming language တစ ခ အ ဖစ ရပ တည နပ ပ အခ အခ မ PHP က THE PHP GROUP က န maintain လ ပ ပ နပ တ ယ ဒ ႔အ ပင PHP ဟ PHP License ရ ႕ အ က မ ထ က ပၚတ ႔free software ဖစ ပ တ ယ PHP ဟ general-purpose scripting language တစ ခ ဖစ ပမယ ႔အထ သ ဖင တ ႔web development အတ က အဓ ကတ င တ င က ယ က ယ အသ ပ ၾက ပ တ ယ သ ႔က HTML coding တ အထ မ ထည သ င အသ ပ င ပ web server ပၚမ run တ ဖစ ပ တ ယ web servers အမ စ မ အသ ပ င ပ တ ႔ Operating System တ န ႔Platform တ အ လ န ပ မ အခ ၾက င ပ စရ မလ ပ ရယ အသ ပ င ပ တ ယ အခ အခ န မ PHP က websites ပ င သ န ၂၅ က န ႔web server ၁ သန က ပၚမ install လ ပ က အသ ပ နၾက ပ ဒ အ ရအတ က ဟ န႔စဥ န ႔အမ တ လ ႔လ နပ တယ သ ႔ရ ႕ syntax ဟ Perl န ႔ C တ န ႔ဆ င တ ပ တ ယ operating system အ တ မ မ ပၚမ Apache (web server) န ႔ အတ တ တ ပ အသ ပ ၾကပ တ ယ Windows ပၚမ လည Microsoft ရ ႕IIS န ႔လည ယ ဥ တ အသ ပ င ပ တယ official current release က တ ႔PHP (March 4, 2010) ဖစ ပ တ ယ အခ ဒ စ ရ နစဥ latest preview release က တ ႔5.3.3 rc3 (July 15, 2010) ဖစ ပ တ ယ PHP 4 က န PHP 5 က ပ င လ တ ႔အခ မ object-oriented programming language ဖစ လ ခ ႔ပ တ ယ အခ အခ မ တ ႔ ကမ ၻ ပၚမ ရ တ ႔ ဘ သ စက အ လ န ပ ရ ႕ အက ၡရ တ က က င တ ယ င ပ လ ႔ဆ င ပ တ ယ PHP ဟ သ ႔ရ ႕ ယ ဥ ပ င ဘက language တ ထ က ပ က င တ ယ ပ မန တယ သင ယ ဖ ႔ပ မ လ ယ က တယ လ ႔အၾက မ အ ဖင ပ င ပ တ ယ database အ တ မ မ န ႔ယ ဥ တ အသ ပ င ခင ပ ႔ပ ခင အက န ႔အသ န ႔မရ ဘ လ ႔ ပ င လ က အ င ခ ႕ထ င အသ ခ င ခင open source ဖစ သ ၾက င က န က စရ တ မရ ခင စတ ႔ က င က မ စ ရ န ပ တယ က ၽ န တ PHP စ အ ပ က အခ ရ ပမယ ႔JSP, ROR န ႔ ASP.net တ ႔က လ ည လ႔လ နတ ပ ဖစ ပ တ ယ တစ ခ စ တ င မ တ ႔ အ သ ခ က အ နည ခ က က ယ စ ရ ၾကတ မ ဖစ ပ တ ယ ဘယ အရ က မ ရ န ပည က င မ န တ ယ လ ႔မဆ င ပ ဘ.. PHP အလ ပ လ ပ ပ PHP သည server-side language ဖစ ပ တ ယ ဆ လ တ က က ၽ န တ တ ႔ ရ လ က တ ႔code တ ဟ server ပၚမ run တ ဖစ ပ တ ယ server-side language တ က web page တ ဆ က နပ ႔ ပ လ က တ ႔အခ က အလ က တ က ရယ ပ တ ယ host ရ ႕server ဆ က ရ က လ မယ ရ က လ တ ႔information ပၚမ မ တ ည ပ တ ႔server ပၚမ run ပ တ ယ ပ မ browser ဆ က လ အပ တ ႔အခ က အလ က က ပန ပ ႔ ပ ပ တယ ဥပမ ကၽ န တ တ ႔က web page ပၚမ click တစ ခ က ပ လ က ရင ကၽ န တ တ ႔အ ဒ click ပ လ က ခင ၾက င ရလ တ ႔result က မ မင ရခင မ server ဆ က ကၽ န တ တ ႔ရ ႕ Input ပ လ က တ ႔ အခ က အလက တ က ပ ႔တ ရယ server က န ပန ပ ႔တ တ လ ပ နတ ဖစ ပ တ ယ ဒ က server-side ရ ႕သ ဘ ပ client-side language က တ ႔ကၽ န တ တ ႔user တ အသ ပ တ ႔client ပၚမ ပ တ က ရ က run တ ပ JavaScript ရ ႕client က တ ႔web browser ပ ႔ ဒ ၾက င သ ႔အ နန ႔web server ဆ က information ပ ႔တ 5 Youth Dreams 5

6 ပန ထ တ တ တ လ ပ ဖ ႔မလ ပ ဘ သ ဘ တရ က တ ႔browser က code က ဖတ တ ယ ပ ရင interprets လ ပ တ ယ ပ ရင ပန ထ တ ပတ ယ မန မန ဆ န ဆန ပ ပ တ ယ သ ႔ နရ န ႔သ တ ႔client-side ရ server-side ရ လ အပ ပ တ ယ ဥပမ form တစ ခ ဆ ပ စ ႔ဗ ကၽ န တ တ ႔sign up လ ပ တ ႔အခ ဖစ ဖစ ပ ႔က ၽ န တ တ ႔text box ထ မ ထ ည လ က တ ႔ data တ က မ န မမ န က client side language တစ ခ န ႔စစ မယ valid ဖစ မ ဖစ က ပ ႔ ပ မ submit က ဖစ ဖစ ပ လ က မ server ဆ က ပ ႔မ ပ ႔ server ဆ က မ န ကန တ ႔information တ ပ ရ က ရ စတ ပ ႔ဗ web server ပၚမ အခ က အလ က တ က save လ ပ ပ သ မ ထ ဖ ႔လ အပ တ မ ၾက တ ႔server side န ႔ပ လ ပ လ ႔ရတ ပ ႔ Fig 1.1 PHP က အသ ပ ထ သ server ထ မ user က web page က request လ ပ ပ PHP က လ ႔လ တ မယ ဆ ရင Apache web server န ႔My SQL Database တ ႔ပ တ ပ ပ နတ ဖစ ပ တယ အခ က ၽ န တ တ ႔PHP က စတင လ ႔လ ဖ ႔အတ က လ အပ တ ႔software က သ င ရပ မယ localhost မ သ ဖ ႔အတ က လ အပ တ ႔software တ အ လ က ပ င စ ပ ထည ထ တ ႔package software တ ရ ပ တ ယ အ ဒ software တ က သ ပ web server န ႔database က က ယ ႔စက ထ မ ပ ရရ မ ဖစ ပ တ ယ အ ဒ software တ ထ မ windows အတ က ထ င ရ တ တ က တ ႔WAMP န ႔XAMPP တ ႔ပ ဖစ ၾက ပ တ ယ သ ႔ထ မ apache, mysql, php စတ ႔လ အပ တ တ အ လ ပ ၀င တ ဖစ ပ တ ယ ကၽ န တ တ ႔အခ XAMPP က ပ ရ ပ တ ႔ လ႔လ ၾကပ မယ ၁ က သ ပ တ ႔က ယ ႔ရ ႕windows version န ႔က က ည တ ႔ xampp installer က ဒ င လ ပ ဆ ပ အဆင ဆင သ င သ လ က ရင ရသ မ ပ သ မန software သ င သလ ပ ပ ခင ဗ သ င ပ သ ရင တ ႔C အ က က xampp အ က က htdocs အ က မ php ဆ တ ႔folder လ ဆ က သင ပ တယ အ ဒ အ က မ ပ က န တ ႔ ရ သ မ က save သ င ပ တယ PHP စ အ ပ တ စ အ ပ ဖစ တ ႔အတ က လ ပ တတ သင တ ယ လ ႔လည ယ ဆတ ႔အတ က PHP, Apache န ႔MySQL တ ႔က သ ခ စ Install လ ပ တ ႔ပ စ က Part (II) စ အ ပ မ ရ ပ ပ မယ အခ က န တ ႔ အလ ပ ဖစ ဖ ႔အတ က န ႔လ ယ လ ယ က က မန မန ဆန ဆ န လ႔လ င ဖ ႔XAMPP န ႔ပ သ ဖ ႔က န ရ လ က တ ပ န က ထပ ဒ စ အ ပ မ ပ တ ႔သင ခန စ မ က လ ႔လ င ဖ ႔အတ က Web Browser (firefox, IE) တ စ ခ လ ပ မယ text editor တ စ ခ လ ပ မယ PHP editor တ စ ခ ဆ ပ က င ပ တယ က ၽ န တ က တ ႔Dream weaver CS 4 က အသ ပ ပ တ ယ ဒ ပမယ ႔လ ည Notepad က ပ အသ ပ မယ ဆ ရင လ ည အဆင ပ င ပ သ တယ 6 Youth Dreams 6

7 Chapter 2.The Building Blocks of PHP Basic PHP Syntax PHP က ရ တ ႔အခ န ႔စ ပ န ႔အဆ သတ လ႔ရ ပ တယ PHP block တစ ခ က document ရ ႕ဘယ နရ မဆ ထည လ ႔ရပ တ ယ အတ က က အ နန ႔ <? န ႔စ ပ န ႔ဆ ရင တ ႔ရပ တ ယ ဒ ပမယ ႔ အရ ည ရ တ က ပ အ ပ ပ တယ PHP file တ စ ခ မ ပ မ န အ ဖင HTML ဖ င တ စ ခ လ ပ HTML tag တ ပ ၀င ပ တယ PHP code တ လ ည ပ ၀င ပ တ ယ အ က က PHP script က ၾကည မယ ဆ ရင ဒ ဟ browser က Hello World ဆ တ ႔စ သ လ က ထ တ ပ ပ တ ႔code လ ပ ဖစ ပ တ ယ <html> <body> echo "Hello World"; </body> </html> ဒ code လ တ က run မယ ဆ ရင Dreamweaver က ဖ င PHP က ရ ပ တ ႔အလ အ လ က နဂ ရ နတ ႔code တ က ဖတ င ပ တ ယ Notepad က ပ သ ရင လ ည ရပ တ ယ အ ဒ န က code တ က copy paste လ ပ ပ ပ ရင save လ ပ ပ.. save လ ပ ရမယ ႔ နရ က တ ႔C အ က က xampp အ က က htdocs အ က က php ရ ႕ အ က မ ဖစ ပ တ ယ အဆင ပသ လ န မည ပ င ပ တယ ကၽ န တ က တ ႔1.php, 2.php အစရ သ ဖင ပ ပ ထ ပ တ ယ အ ဒ က browser မ ၾက ည မယ ဆ ရင အစရ သ ဖင ခၚ ပ ၾက ည လ ႔ရပ ပ PHP code တ ရ ႕အဆ သတ တ င မ semicolon န ႔အဆ သ တ ရပ မယ semicolon က စ ၾက င တ စ ၾက င န ႔ န က တစ ၾက င က ခ န ပ တ ႔separator သ ဘ ပ ပ PHP က သ ပ တ ႔text စ သ တ က output ထ တ တ ႔အခ အသ ပ င တ ႔အ ခခ statements စ မ ရ ပ တ ယ echo န ႔print ပ အထက ပ ဥပမ မ တ ႔echo က သ ပ Hello World ဆ တ ႔စ သ က output ထ တ ထ ပ တယ မ တ သ ရမ က တ က ယ လ ႔ဖ င က save လ ပ တ ႔အ ခ.php န ႔မသ မ ပ န ႔.html န ႔သ မ မယ ဆ ရင အထ က PHP code တ ဟ အလ ပ လ ပ မ မဟ တ ပ ဘ Comments in PHP PHP မ single line comment အတ က // က အသ ပ ပ တ ယ စ ၾက င ရမ တ ယ ဆ ရင တ ႔/* န ႔စ ပ */ န ႔ဆ ပ တယ 7 Youth Dreams 7

8 <html> <body> //This is a comment /* This is a comment block */ </body> </html> PHP Variables variable တ က number တ strings တ arrays တ function result တ စတ ႔ တန ဖ တ က သ မ ဖ ႔အတ က အသ ပ ပ တယ ဒ လ variable တ စ ခ က ၾက င ထ ခ ႔မယ ဆ ရင သ ႔က က ၽ န တ တ ႔ရ ႕php script ထ မ ထပ ခ ထ ပ ခ ပန ခၚသ င တ ဖစ ပ တ ယ PHP ရ ႕variable တ အက န လ က $ သ က တ န ႔စရပ တ ယ $var_name = value; တက ယ လ ႔$ သ က တန ႔မစဘ ဆ ရင အလ ပ လ ပ မ မဟ တ ပ ဘ အခ string variable တစ ခ န ႔number variable တစ ခ က ရ ၾက ည ပ မယ $txt = "Hello World!"; $number = 10; PHP မ variable တစ ခ က ဘ data type ဖစ တ ယ ဆ တ ၾက တင ၾက င စရ မလ ပ ဘ အထက က ဥပမ လ မ ဒ variable ဟ ဘ data type ဖစ တယ ဆ တ မ က န တ ႔ မ ၾက င ခ ႔ပ ဘ သ ႔က က န တ ႔ ပ ထ ခ ႔တ ႔ တန ဖ ပၚမ မ တည ပ မ န က န တ ႔data type က PHP က အလ အ လ က ပ င ပ မ ဖစ ပ တ ယ Java လ မ Strong type language မ ဆ ရင တ ႔အသ မ ပ ခင မ သ ႔ရ ႕ data type က ၾက တ င ၾက င ပ ရတ ဖစ ပ တ ယ variable က အမည ပ တ ႔အခ သ ႔ရ ႕ဥပ ဒ တ ရ ပ တ ယ - variable name တ စ ခ က letter တစ ခ ခ ဒ မ မဟ တ underscore _ န ႔စတင ရပ မယ - variable name တစ ခ မ alpha-numeric characters န ႔underscores (ဆ လ တ က a-z, A-Z, 0-9, န ႔_ ) တ ႔ပ ပ ၀င ရပ မယ 8 Youth Dreams 8

9 - variable name တ စ ခ မ space တ မပ ၀င ရပ ဘ variable name စ လ ( word ) တစ ခ ထ က ပ တ ယ ဆ ရင underscore (_) န ႔($my_string) ဒ မ မဟ တ capital letter န ႔($myString) ခ န ထ သ င ပ တ ယ Strings in PHP String variable တ စ ခ က text (character stings) တ က သ မ ဆ ည ဖ ႔အလ ပ လ ပ ဖ ႔အတ က အသ ပ ပ တ ယ string တ န ႔ပတ သ တ ပ အသ မ တ ႔function တ န ႔operators တ က န န လ႔လ ၾကည ပ မယ String တစ ခ က ဖန တ ပ တ ႔အခ သ ႔က တ က ခ က င ပ တ ယ string တစ ခ က function တ စ ခ ထ မ တ က ရ က အသ ပ င သလ variable တစ ခ အ ဖစ န ႔လ ည သ မ ဆည င ပ တ ယ အ က က ဥပမ မ Hello World ဆ တ ႔ String က $txt ဆ တ ႔string variable ထ က တ န ဖ assign လ ပ ထ တ ဖစ ပ တ ယ $txt = "Hello World"; echo $txt; သ ႔ရ ႕output က တ ႔Hello World ဖစ ပ တယ အခ string တ က function န ႔operators တ စ ခ ႕က သ ပ manipulate လ ပ တ ႔ပ စ က ၾက ည ပ မယ The Concatenation Operator PHP မ string န ႔ပတ သတ တ ႔operator တ စ ခ ပ ရ ပ တယ concatenation operator ဆ တ ႔(.) က string value စ ခ က အတ တ က ဖစ သ အ င လ ပ ဖ ႔အတ က အသ ပ ပ တ ယ dot (.) operator က အသ ပ ပ string စ ခ က ပ င တ ႔ပ စ က အ က မ ၾက ည ပ $txt1="hello World"; $txt2="12345"; echo $txt1. " ". $txt2; သ ႔ရ ႕output က တ ႔Hello World ပ ဖစ ပ တယ က န တ ႔ရ ႕code က ၾက ည မယ ဆ ရင concatenation operator (.) က စ ၾက မ အသ ပ ထ တ က တ ႔မ ဖစ ပ တယ တ တ ယ string ဖစ တ ႔ (empty space) က ထ ည ခ င လ ႔ပ ဖစ ပ တ ယ Using the strlen() function strlen() function က string ရ ႕အရ ည length က သ ရ လ တ ႔အခ မ အသ ပ ပ တယ Hello World! ဆ တ ႔string ရ ႕ length က ရ မယ ဆ ရင 9 Youth Dreams 9

10 echo strlen("hello World!"); သ ႔ရ ႕ output က တ ႔ 12 ပ ဖစ ပ တ ယ string ရ ႕ length က looping တ န ႔ တ ခ function အ တ မ မ မ အသ ပ ဖ ႔လ အပ ပ တယ Using the strpos() function strpos() function က string တစ ခ အထ မ ရ တ ႔character တ စ ခ ဒ မ မဟ တ န က string တ စ ခ က ရ ဖ ႔အတ က အသ ပ ပ တ ယ echo strpos("hello World!", "World"); သ ႔ရ ႕output က တ ႔6 ပ ဖစ ပ တ ယ World ရ ႕ နရ တ နည အ ဖင W ရ ႕ နရ က 6 ဖစ နပ တ ယ ဘ လ ႔7 မ ဖစ ရတ လ ဆ တ ႔string တ စ ခ ရ ႕ပထမposition ဟ 1 မဟ တ ပ ဘ 0 ဖစ လ ႔ပ ပ PHP မ string အတ က function ပ င မ က မ စ ရ ပ တ ယ အခ တ ႔အ ခခ ဖစ လ ႔ဒ လ က ထ ပ ထ ည လ က ပ တယ PHP Operators အ က မ PHP မ သ တ ႔operator တ ပ ဖစ ပ တ ယ Arithmetic Operators Arithmetic Operators တ အ နန ႔ဥပမ တ စ ခ လ က run ၾက ည ပ မယ $no1=2; 10 Youth Dreams 10

11 $no2=3; $no3= $no1+$no2; echo $no3; ဒ code က run ရင output 5 ရပ မယ အ ပ င အ တ အ မ က က တ ႔ရ င ပ တ ယ Division ဆ တ ႔အစ မ တ ႔15 က 5 န ႔စ ရင သ ရပ မယ 5 က 2 န ႔စ ရင 2.5 ရလ ဒ ရပ မယ $no1=5; $no2=2; $no3= $no1/$no2; echo $no3; Modulus ဆ တ က တ ႔အ ၾက င က ရ တ ဖစ ပ တယ 5%2 ဆ ရင 1 ရပ မယ.. 10%2 ဆ ရင 0 ရပ မယ $no1=5; $no2=2; $no3= $no1%$no2; echo $no3; Assignment Operators Assignment Operators တ က တ ႔အတ ရ တယ လ ႔ ပ ရမ ပ.. PHP မ သ တ ႔ပ စ တ ပ ႔ x=x+y ဆ ရင xန ႔y န ႔ ပ င ပ ရတ ႔တန ဖ က x ထ ထည ပ လ ႔ဆ လ ပ တယ အ ဒ က PHP မ assignment operator သ ပ တ ႔x+=y လ ႔ ရ ပ တယ ဥပမ တ စ ပ ဒ လ က run ၾကည ပ 11 Youth Dreams 11

12 $x=5; $y=2; $z= $x+=$y; echo $z; Output က 7 ရပ မယ Comparison Operators Comoparison Operators တ က တ ႔တ န ဖ ခင င ယ ဥ ပ မယ အမ န န ႔အမ ဆ ပ ရလ ဒ စ ခ ပန ထ တ ပ ပ တ ယ == ဆ ရင ည သလ လ ႔စစ ပ တ ယ ဥပမ 5 က 8 န ႔ည သ လ ဆ ရင 5==8 လ ႔စစ ပ မယ result က တ ႔false ထ က ပ မယ $x=5; $y=2; if ($x==$y) echo true ; else echo false ; အထက ပ code က run မယ ဆ 5 န ႔2 န ႔မည တ ႔အတ က false ရပ မယ အ က ကအတ င variable x ရ y ရ 3 ဆ ပ တ နတ ႔အတ က run တ ႔အခ output true ရပ မယ $x=3; $y=3; if ($x==$y) echo "true"; else echo "false"; 12 Youth Dreams 12

13 Logical Operators Logical Operators တ အတ က လ ည အထ က ပ ဇယ က ၾကည ရင န လ ည မ ပ.. ဒ Operator တ က အ ရ ႕မ တ ဖည ဖည န ႔အသ ပ ရင သခ န လ ည လ ပ လ မ ႔မယ 13 Youth Dreams 13

14 Chapter 3.Flow Control Functions in PHP PHP If Else Statements PHP မ if, elseif န ႔else statements တ က မတ ည တ ႔condition တ ပၚမ မတ ည တ ႔လ ပ ဆ င ခ က တ က ဆ င ရ က ဖ ႔အတ က အသ ပ ပ တ ယ Conditional Statements က န တ ႔coding ရ တ ႔အခ မ မၾက ခဏ ဆ သလ မတ ည တ ႔ဆ ဖတ ခ က တ အတ က မတ ည တ ႔လ ပ ဆ င မ တ က ဆ င ရ က လ ၾက ပ တယ အ ဒ လ လ ပ ဆ င င ဖ ႔အတ က conditional statements တ က အသ ပ ၾကရပ တ ယ The if else statement အ ခအ နတစ ခ က မ န တယ ဆ ရင ဒ code က ဆက run ပ.. တကယ လ ႔မ တယ ဆ ရင ဒ ဘက က code က ဆက run ပ ဆ တ မ အတ က ဒ if else statement က အသ ပ ပ တ ယ သ ႔ရ ႕syntax က တ ႔ အ က ဖ ပပ ပ စ မ ဖစ ပ တ ယ if (condition) code to be executed if condition is true; else code to be executed if condition is false; ဒ ဟ က ဥပမ တ စ ခ န ႔ၾက ည မယ ဆ ရင <html> <body> $d=date("d"); if ($d=="fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; </body> </html> ဒ code က run ၾကည မယ ဆ ရင တ ကယ လ ႔ဒ န႔က သ ၾက န႔ ဖစ ရင Have a nice weekend လ ႔ ပၚမ ဖစ ပ တ ႔ တ ခ န႔ဆ ရင တ ႔Have a nice day လ ႔ ပၚမ ဖစ ပ တ ယ က န အခ run တ တ ႔Have a nice weekend လ ႔ ပၚပ တယ ဒ န႔က သ ၾက န႔ ဖစ နလ ႔ပ.. အ ဒ န ႔Computer ရ ႕System Date က Tuesday လ ႔ ပ င ပ က န ပန run ပ တယ Have a nice day လ ႔ ပၚပ တ ယ ခင ဗ :) 14 Youth Dreams 14

15 တက ယ လ ႔မ condition တစ ခ က မ န တယ ဒ မ မဟ တ မ တယ ဆ တ ႔အခ မ တ စ ၾက င ထက ပ တ ႔code တ က run စခ င တယ ဆ ရင တ ႔curly braces ဆ တ ႔ ထ မ ထည ထ ရမ ဖစ ပ တယ ဥပမ <html> <body> $d=date("d"); if ($d=="fri") echo "Hello! <br/>"; echo "Have a nice weekend!"; echo " See you on Monday!"; </body> </html> ဒ code လ ရ ႕output က တ ႔ Hello! Have a nice weekend! See you on Monday! ဖစ ပ တ ယ ခင ဗ Computer System Date က သ ၾက ဖစ မ နဘ ဆ ရင တ ႔ ပၚမ မဟ တ ဘ န.. The elseif statement တစ ခ ထက ပ တ ႔condition တ အမ ၾက ထ က တစ ခ ခ က မ န နရင code က run စခ င တ ယ ဆ ရင elseif statement က အသ ပ ပ တ ယ သ ႔ရ ႕syntax က တ ႔ if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false; ဒ လ ပ စ ဖစ ပ တ ႔ဥပမ ပရရင <html> <body> 15 Youth Dreams 15

16 $d=date("d"); if ($d=="fri") echo "Have a nice weekend!"; elseif ($d=="sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; </body> </html> တက ယ လ ႔ဒ န႔က သ ၾက ဖစ ရင Have a nice weekend! လ ႔ ပပ မယ တ နဂ ဖစ နရင Have a nice Sunday! လ ႔ output ပမ ဖစ ပ တ ႔တ ခ န႔တစ ရက ရက ဆ ရင တ ႔Have a nice day! လ ႔ပ ပမ ဖစ ပ တ ယ The Switch Statement အ ခအ နတ စ ခ က မ တ ည ထ မယ အ ဒ အ ခအ န ပၚမ မ တည ပ မ န က န တ ႔အခ ဘ ယ code က run ရမယ ဘယ case န ႔က က ည တ ယ ဆ တ က စစ တ ဖစ ပ တ ယ switch case statement က သ တ ႔အခ မ if elseif else statement တ အရ ည ၾက သ ရတ တ က နလည သက သ စပ တယ သ ႔ရ ႕Syntax က အ က ဖ ပပ အတ င ဖစ ပ တယ switch (expression) case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; ဥပမ က run ၾက ည မ သ သ ဘ ပ က င မ ဖစ ပ တယ <html> <body> 16 Youth Dreams 16

17 $x=4; switch ($x) case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; </body> </html> ဒ code က run လ က ရင No number between 1 and 3 လ ႔ရမ ဖစ ပ တ ယ $x=4 လ ႔တ န ဖ သ က မ တ ပ ထ ခ ႔တ ၾက င ပ.. တက ယ လ ႔$x=2 လ ႔assign လ ပ ခ ႔ရင Number 2 လ ႔output ပမ ဖစ ပ တယ သ ႔ရ ႕အလ ပ လ ပ ပ က တ ႔single expression တ စ ခ အမ အ ဖင တ ႔variable တစ လ က တ စ ၾက မ evaluate လ ပ တ ယ.. code တ ထ မ ပ တ ႔case တစ ခ စ ထ က တ န ဖ န ႔expression ရ ႕တန ဖ န ႔က င ယ ဥ တ ယ က က ည တယ ဆ လ ႔ရ ရင အ ဒ case န ႔ဆက ယ တ ႔code က execute (run) တ ယ execute လ ပ ပ တ ႔အခ န က case တစ ခ က ဆ က ပ မrun တ ႔ လ အ င break က သ ပ ထ က တ ယ တက ယ လ ႔case တ အ လ က မမ န ဘ ဆ ရင default statement က execute လ ပ သ မ ပ ဖစ ပ တယ PHP Arrays array တစ ခ က variable name တ စ ခ လ ထည မ ပ တ စ ခ သ ႔မဟ တ တ စ ခ ထက ပ တ ႔ တ န ဖ တ က သ မ ဆည ပ ပ တယ က န တ ႔အ နန ႔တ ခ တ ရ မ ဆ င တ တ ႔variable တ အမ ၾက က ဖန တ လ တ ႔အခ မ ရ လ ပ တယ အ ဒ အခ မ variable တ အမ ၾက မဖန တ တ ႔ပ န ႔array တစ ခ ထ မ ပ elements တ အ နန ႔သ မ လ က င ပ တယ array ထ မ ရ တ ႔element တစ ခ စ မ သ ႔ရ ႕က ယ ပ င အမ တ (ID) ရ မ ဖစ တ ႔အတ က လ ယ က စ ခၚသ င ပ တယ array အမ အစ သ မ ရ ပ တယ -Numeric array ID key က န ပ တ န ႔ ပ တ ႔array မ -Associative array- ID key တ တ စ ခ စ တ င က တ န ဖ တ စ ခ န ႔ဆက စပ နတ ႔array မ 17 Youth Dreams 17

18 -Multidimensional array- တစ ခ သ ႔မဟ တ တ စ ခ ထက ပ တ ႔array တ ပ ၀င နတ ႔array မ န လည သ အ င တ စ ခ ခ င စ က ဥပမ န ႔ၾက ည ၾကပ မယ Numeric array numeric array တ စ ခ က နည လ မ အမ မ န ႔ဖန တ င ပ တယ $names = array("mgmg","mama","koko"); ဒ စ ၾက င မ ဆ ရင ID key က အလ အ လ က သတ မ တ ပ မ ဖစ ပ တ ယ အ က က code မ တ ႔က န တ ႔က manual သ တ မ တ ပ တ ဖစ ပ တယ $names[0] = "MgMg"; $names[1] = "MaMa"; $names[2] = "KoKo"; အ ဒ စ မ စ လ ရ ႕အက သက ရ က မ က တ ႔အတ တ ပ ပ PHP coding ထ မ ထည သ ၾက ည မယ ဆ ရင > $names[0] = "MgMg"; $names[1] = "MaMa"; $names[2] = "KoKo"; echo $names[1]. " and ". $names[2]. " are ". $names[0]. "'s neighbours"; output အ နန ႔MaMa and KoKo are MgMg's neighbours ဆ ပ ရလ မ ဖစ ပ တယ Associative Arrays associative array မ ID key တ စ ခ စ ဟ တ န ဖ တ စ ခ စ န ႔ဆ က ယ ပ တ ယ တ က တ ႔တ န ဖ တစ ခ ႕န ႔ပတ သ တ တ ႔ ဒတ တ က သ မ ဆည တ ႔အခ numerical array က အ မ တ မ အ က င ဆ နည လ မ မဟ တ ပ ဘ associative arrays က သ တ ႔အခ မ တ န ဖ တ က key အ နန ႔ပ သ င ပ တ ႔array မ တန ဖ တ က assign လ ပ င ပ တ ယ ရ င သ အ င ဥပမ က ၾကည ပ မယ ဒ ဥပမ မ က န တ ႔ဟ လ တ စ ယ က စ က သ တ ႔ရ ႕အသ က က array က သ ပ assign (တန ဖ သ တ မ တ ) ပ တ ယ $ages = array ("MgMg"=>18,"MaMa"=>20,"KoKo"=>19); အ က ကပ စ န ႔လည ရ င ပ တ ယ.. က ဖန တ တ ပ ပ အဓ ပၸ ယ က တ ႔အတ တ ပ ပ ရ တ ႔ပ စ က သ တ ပ သ က လည array $ages['mgmg'] = "18"; 18 Youth Dreams 18

19 $ages['mama'] = "20"; $ages['koko'] = "19"; ဒ code တ က PHP ထ မ ထ ည ရ တ ႔အခ > $ages['mgmg'] = "18"; $ages['mama'] = "20"; $ages['koko'] = "19"; echo "KoKo is". $ages['koko']. " years old."; သ ႔ရ ႕output က တ ႔KoKo is19 years old. ပ ဖစ ပ တယ Multidimensional Arrays multidimensional array တ စ ခ ထ မ အဓ က array ၾက ရ မယ.. အ ဒ အ ဓ က array ၾက ထ က element တစ ခ စ က လ array ဖစ င တယ အ ဒ sub array တ စ ခ စ ထ က elelment တ က လ ည array ထ ပ ဖစ င တယ.. ထပ ဆ င ထ ပ ဆင ပ ႔ $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) ); echo "Is ". $families['griffin'][2]. " a part of the Griffin family?"; 19 Youth Dreams 19

20 အထက ပ php code က ၾက ည ရင $families ဆ တ ႔variable ထ မ array တ စ ခ ဆ က ပ တ ယ Griffin, Quagmire, Brown ဆ တ ႔သ ခ ပ ၀င ပ တ ယ Griffin ရ ႕အထ မ Peter, Lois, Megan ဆ တ ႔array သ ခ ထပ ဆ င ဆ က ထ သ လ Quagmire ထ မ Glenn Brown ထ မ Cleveland, Loretta, Junior ဆ ပ သ ခ ထ ပ ပ နတ တ ႕ရပ တ ယ ဒ ဟ က run လ က ရင Output က Is Megan a part of the Griffin family? ရမ ဖစ ပ တယ Griffin array ရ ႕န ပ တ စ အခန က Megan ဖစ ပ တယ Peter က န ပ တ ၀ Lois က န ပ တ ၁ ဖစ ပ တ ယ PHP Looping code အပ င လ တ စ ခ က အၾက မ မ စ run ဖ ႔အလ ရ တ ႔အခ looping က သ ရပ တ ယ PHP မ အ က ဖ ပပ looping statements မ ရ ပ တယ while - အ ခအ နတ စ ခ မ န နပ က ဖ ပပ code က run ပ မယ မ န နသ ရ ႕ဆ က run နမ ဖစ ပ တယ do while - တစ ၾက မ တ ႔ ဖ ပပ code က သခ ပ က run ပ မယ.. အ ဒ န က မ မ အ ခအ နက မ န နသ ရ ႕ထပ ခ ထ ပ ခ ဆ က run ပ မယ for - သ က မ တ ထ တ ႔အၾက မ အ ရအတ က အတ င ဖ ပပ code က ထပ ခ ထ ပ ခ run နပ မယ foreach array တ စ ခ ထ မ ရ တ ႔element တစ ခ စ အတ က ဖ ပပ code က run ပ မယ တစ ခ ခ င ဆ က အ သ စ တ ၾကည ၾက ရ အ င The while Statement အ ခအ နတ စ ခ မ န နပ က ဖ ပပ code က run ပ မယ မ န နသ ရ ႕ဆက run နမ ဖစ ပ တ ယ Syntax while (condition) code to be executed; Example ဖ ပပ code လ က variable i အ နန ႔၅ထ က ငယ နဒ မ မဟ တ ည နသ ရ ႕ဆ က ပ တ ႔တ စ ၾက မ ပ တစ ၾက မ looping ပတ နမ ဖစ ပ တ ယ တစ ၾက မ loop ပတ ပ တ င မ i ရ ႕တ န ဖ က ၁တ တ လ ပ မယ <html> <body> $i=1; while ($i<=5) echo "The number is ". $i. "<br/>"; $i++; 20 Youth Dreams 20

21 </body> </html> output အ နန ႔- The number is 1 The number is 2 The number is 3 The number is 4 The number is 5 ဆ ပ ရလ မ ပ အရင ဆ variable i လ က 1 assign လ ပ ထ ပ ပ တ ယ.. အ ဒ န က i က င ထက ငယ လ ည လ လ ႔စစ ပ တ ယ.. i ရ ႕တန ဖ က ၁ ဖစ နတ ႔အတ က ငယ ပ တယ ဒ ၾက င ထ က code တ က အလ ပ လ ပ ပ တယ The number is 1 ဆ တ ႔တစ ၾက င output ထ က ပ တယ <br/> ၾက င အ က တစ ၾက င ဆ င ပ တ ယ.. i ရ ႕တန ဖ က တ စ တ တ ႔အတ က i တန ဖ က 2 ဖစ သ ပ တယ.. က ရ က တ ႔အခ while မ တ စ ခ ထ ပ သ စစ ပ တယ.. i က င ထ က ငယ န သ တ ႔အတ က ထပ အလ ပ လ ပ ပ တ ယ.. The number is 2 ဆ ပ ထ က ပ တ ယ.. ဒ လ န ႔i ရ ႕တ န ဖ ၆ ဖစ သ တ ႔အထ လ ပ ပ တယ ၆ ဖစ သ တ ႔အခ while မ ထပ စစ တ ႔ င ထ က မငယ သလ မည တ ႔တ ႔အတ က.. ထ က code က အလ ပ မလ ပ တ ႔ပ ဘ.. န လည မယ လ ႔ မ လင ပ တ ယ The do while Statement တစ ၾက မ တ ႔ ဖ ပပ code က သ ခ ပ က run ပ မယ.. အ ဒ န က မ မ အ ခအ နက မ နရင ဆ က မrun တ ႔ပ ဘ.. မ န နသ ရ ႕ တ ႔ထ ပ ခ ထပ ခ ဆက run ပ မယ Syntax do code to be executed; while (condition); Example ဖ ပပ ဥပမ မ အရင ဥ ဆ a က တ စ တ ပ တယ အ ဒ န က မ a ရ ႕တ န ဖ က ၅ထက ငယ နသ ရ ႕ဆ က ပ တစ တ သ မ ဖစ ပ တ ယ <html> 21 Youth Dreams 21

22 <body> $a=0; do $a++; echo "The number is ". $a. "<br/>"; while ($a<5); </body> </html> အ သ စ တ အလ ပ လ ပ ပ က တ ႔variable a ထ က သ ညထ ည ပ တယ အ ဒ န က do ထ က code တ က အ လ ပ လ ပ ပ တယ.. a က တ စ တ တ ႔အတ က a က တ စ ဖစ သ ပ တ ယ echo ၾက င The number is 1 လ ႔ထ က မ ဖစ ပ တ ယ.. <br/> ၾက င အ က တ စ လ င ဆင ပ တယ.. a က င ထက ငယ န သ တ ႔အတ က do ဆ က ပန သ ပ do က ထ ပ အလ ပ လ ပ ပ တယ.. a က င ထက ၾက သ တ ႔အခ ၾက မ looping က နထ က သ ပ တယ.. သ ႕ရ ႕output က The number is 1 The number is 2 The number is 3 The number is 4 The number is 5 ပ ဖစ ပ တ ယ The for Statement ရ ရ ပ ရရင တ ႔code အပ င လ တ စ ခ က ဘ ယ စ ၾက မ run စခ င တ ယ ဆ တ မ က က န တ ႔သ ထ တ ႔အခ မ for statement က သ ပ တယ သ ႔ရ ႕syntax က တ ႔ for (init; cond; incr) code to be executed; init ဆ တ က initial value က ပ တ ပ.. မ လ အစတန ဖ ပ ႔ cond က တ ႔condition ပ ႔ အ ဒ condition မ န နသ မ အလ ပ လ ပ ပ မယ မ သ တ န ႔loop ထ က နထ က ပ မယ incr က တ ႔မ လ တန ဖ init က တ ပ တ ႔increment ပ ႔ အ က က တ ႔Hellow World! ဆ တ ႔စ သ က ဆယ ၾက မ ပ ပ မယ ႔ဥပမ လ ပ <html> <body> 22 Youth Dreams 22

23 for ( $i=1; $i<=10; $i++) echo "Hello World!<br />"; </body> </html> variable i ရ ႕မ လ တန ဖ က 1 လ ႔ ပ ပ စလ က ပ တယ i က 10 ထ က ငယ လ ည နလ စစ ပ တ ယ.. မ န တ ႔အတ က Hello World! တစ ၾက မ ပပ တယ အ က တ စ ၾက င ဆ င ပ တ ယ.. i ရ ႕တ န ဖ က တစ တ ပ တယ.. i က 2 ဖစ သ ပ တ ယ.. 10 ထက ငယ လ ည လ ထ ပ ပ စစ ပ တယ.. ငယ န သ တ ႔အတ က န က ထပ Hello World! တ စ ၾက င ပပ မယ.. ဒ ပမယ ႔program မ ပ သ တ ႔အတ က output တ က မ ပဘ န.. အက န ပ သ မ တ ခ တည ပမ ဟ တ ပ ပ အ ဒ လ န ႔i က တ စ တ လ က 10 ထ က ငယ လ ည လ စစ လ က န ႔ န က ဆ i ရ ႕တန ဖ 11 ဖစ သ တ ႔အခ မ မ.. Looping က နထ က သ ပ တ ယ.. output အ နန ႔Hello World! ဆ တ ႔စ သ ဆယ ၾက င ရရ ပ တ ယ The foreach Statement foreach statement က တ ႔array တ က looping ပတ ဖ ႔အတ က အသ ပ ပ တ ယ သ ႔ရ ႕Syntax (ပ စ ) က တ ႔ foreach (array as value) code to be executed; ဖစ ပ တ ယ အ က က ဥပမ က ၾက ည ရင န လ ည မ ပ <html> <body> $arr=array("one", "two", "three"); foreach ($arr as $value) echo "Value: ". $value. "<br />"; </body> </html> output အ နန ႔-23 Youth Dreams 23

24 Value: one Value: two Value: three ဆ ပ ရပ မယ looping တစ ခ စ တ င အတ က array element ရ ႕တန ဖ က $value ထ က assign လ ပ တယ array ရ ႕pointer က တ စ နရ ပ တစ နရ ရ ႕သ တ ယ န က တစ ၾက မ ထ ပ ပတ တ ႔အခ န က ထပ element တစ ခ ပၚမ အလ ပ လ ပ ပ တ ယ 24 Youth Dreams 24

25 Chapter 4.Working With Functions & Forms PHP Functions အမ န တ ကယ PHP ရ ႕စ မ အ က function တ ပ ပ.. PHP မ built-in နဂ တည က ပ တ ႔functions ပ င 700 က ရ ပ တ ယ ဒ က တ ရ ရယ မ တ ႔function တ စ ခ က ဘ ယ လ ဖန တ တယ ဆ တ က ရ သ သ ပ မယ Creating a PHP Function function ဆ တ code အစ အ ၀ တ စ ခ ပ ပ.. က န တ ႔လ အပ တ ႔အခ န မ သ ႕က ခၚ ပ သ ရမ ဖစ ပ တ ယ function န ႔ပတ သတ ပ မ တ သ ရမ တ က တ ႔- - function တ အ လ က function () ဆ တ ႔စက လ န ႔စတင ရပ မယ - function က အမည ပ တ ႔ နရ မ သ ႔ရ ႕န မည က ၾက ည လ က တ န ႔ဒ function ဟ ဘ လ ပ တ ႔ဟ လ ည ဆ တ က သ သ ထင ရ အ င အမည ပ သ င ပ တ ယ န မည က letter ဒ မ မဟ တ underscore န ႔စတ င သင ပ တယ န ပ တ န ႔မဟ တ ပ ဘ - က function ရ ႕အစမ ထည ရပ မယ ရ ႕အ န က မ တ ႔function ရ ႕code တ က ရ ရပ မယ.. - function က ပ တ တ ႔အခ န ႔ပ တ ရပ မယ အရ င ဆ ပ စ န ႔function ရ ႕ပ စ လ က ရ ၾကည ပ မယ Example <html> <body> function writemyname() echo ""; writemyname(); </body> </html> writemyname() ဆ တ ႔function လ က အရင ဆ က လ က တယ.. သ ႔ရ ႕code က တစ ၾက င ပ ရ ပ တ ယ န မည က screen မ ပ ပ မ ပ ဒ အတ င ပ ထ လ ႔ရ ရင မ ပၚပ ဘ.. function က ပ တ တယ ပ မ writemyname(); ဆ ပ ခၚလ က တ ႔မ အလ ပ လ ပ တ ဖစ ပ တ ယ ပ ပ န လည သ အ င န က ထပ ဥပမ တစ ခ ထ ပ ရ ပ မယ <html> <body> 25 Youth Dreams 25

26 function writemyname() echo ""; echo "Hello World! <br />"; echo "My name is "; writemyname(); echo ". <br /> That's right, "; writemyname(); echo " is my name."; </body> </html> သ ႔ရ ႕output က တ ႔ Hello World! My name is. That's right, is my name. အခ လ က ဆ function ရ ႕အလ ပ လ ပ ပ က န လည မယ လ ႔ မ လ င ပ တ ယ PHP Functions- Adding parameters အခ က န တ ႔ ရ လ က တ ႔writeMyName() ဆ တ ႔function လ က တ ႔အရ ရ င ဆ ပ စ လ ပ သ က string လ တစ ခ က ပ echo လ ပ ပ တ လ ပ function တ စ ခ က ပ မ သ က ၀င လ ပ ရ လ အ င parameters တ က ထည ပ င ပ တ ယ parameter ဆ တ variable လ သ ဘ တ ရ ပ ပ writemyname() ဆ တ ႔function name က ၾက ည မယ ဆ ရင parentheses လ ႔ ခၚတ ႔() က သ တ ထ မ မ ပ paramenter တ က အ ဒ parentheses ရ ႕အထ မ ထ ည ပ ရမ ဖစ ပ တယ Example 1 အခ ဥပမ မ တ ည တ ႔မ ရ န မည တ န ႔မတ ည တ ႔first name န ႔က ရ မ ဖစ ပ တယ <html> <body> function writemyname($fname) echo $fname. "Moe. <br />"; echo "My name is "; 26 Youth Dreams 26

27 writemyname("shwe"); echo "My name is "; writemyname("ngwe"); echo "My name is "; writemyname("sein"); </body> </html> အခ လ output ထ က လ ပ မယ My name is ShweMoe. My name is NgweMoe. My name is SeinMoe အလ ပ လ ပ ပ က တ ႔writeMyName () ဆ တ ႔function ထ မ $fname ဆ တ ႔parameter တ စ လ ထည ပ ထ ပ တ ယ function ထ မ ပ ၀င တ ႔code ကလ ည တစ ၾက င တ ည ပ ပ.. $fname ဆ တ ႔parameter ရ ႕တ န ဖ ရယ သ ႔ရ ႕ န က မ Moe ဆ တ ႔မ ရ န မည ရယ က echo န ႔ရ က ခ င ပ အ က တစ ၾက င ဆင စထ တ ဖစ ပ တယ က န တ ႔က writemyname() ဆ တ ႔function က Shwe ဆ တ ႔parameter လ က ထ ည စ ပ တ ႔writeMyName( Shwe ); ဆ ပ လ မ ခၚလ က တ ႔အခ $fname ရ ႕တန ဖ က Shwe ဖစ သ ပ တ ႔ShweMoe ဆ တ ႔န မည က ဖစ သ စပ တယ က န တ တ လည အလ တ ပ ပ အခ ဆ က ပ တ ႔parameter စ လ ပ တ ႔ဥပမ က ၾက ည ၾကပ မယ <html> <body> function writemyname($fname, $punctuation) echo $fname. "Moe". $punctuation. "<br />"; echo "My name is "; writemyname("shwe", "."); echo "My name is "; writemyname("ngwe","!"); echo "My name is "; writemyname("sein","..."); </body> </html> run လ က တ ႔အခ အခ အတ င ထ က လ ပ တ ယ 27 Youth Dreams 27

28 My name is ShweMoe. My name is NgweMoe! My name is SeinMoe... ပထ မဥပမ အတ င အပ အ၀င $punctuation ဆ တ ႔parameter နရ မ ပ.,!, န ႔ တ ႔က function က ခၚလ က တ ႔အခ တ င တလ ည စ နရ ၀င ယ သ တ ဖစ ပ တ ယ PHP Functions Return Values function တ က တ န ဖ တ က return ပန ဖ ႔အတ က လည အသ ပ င ပ တ ယ <html> <body> function add($x,$y) $total= $x + $y; return $total; echo "1+16=". add(1,16); </body> </html> output =17 ဖစ ပ တယ add () function ထ မ $x န ႔$y parameter စ လ ပ ပ တယ အ ဒ parameter စ လ က ရလ မယ ႔တ န ဖ တ က ပ င ပ $total ထ က ထည တယ.. အ ဒ န က $total က return ပန ပ တ ယ.. add() function က ခၚလ က ရင $total ရ ႕တန ဖ က ပ ပ မ ဖစ ပ တ ယ add(1,16); ဆ ပ တ ႔function က ခၚလ က တ ႔အခ မ function အလ ပ လ ပ ပ ပ.. 1 န ႔16 န ႔က ပ င ပ တ ႔$total ထ က 17 ရ က သ တ ယ.. အ ဒ တန ဖ က return ပန ထ တ ဖစ တ ႔အတ က output မ 1+16=17 ဆ ပ ရလ တ ဖစ ပ တ ယ PHP Forms and User Input user က ရ သ င လ က တ ႔အခ က အလက တနည အ ဖင Form တ က အခ က အလက တ က ရယ ဖ ႔အတ က PHP မ $_GET န ႔$_POST ဆ တ ႔variable တ က အသ ပ ပ တယ HTML form တ PHP form တ န ႔အလ ပ လ ပ တ ႔အ ခ အ ရ အၾက ဆ သတ ထ ရမ က တ ႔HTML Page တ စ ခ ထ မ form element တ အက န လ ဟ PHP code ထ မ အလ အ လ က အသ ပ င မ ဖစ ပ တယ ဥပမ - <html> <body> <form action = "welcome.php" method="post"> Name: <input type="text" name="name"/> Age:<input type="text" name ="age"/> <input type="submit"/> </form> 28 Youth Dreams 28

29 </body> </html> ဒ code လ က form1.html လ ႔save လ က ပ မယ ဒ ဥပမ လ မ input field စ ခ န ႔button လ တ စ ခ ပ ပ တ ယ user က form ထ မ ဖည ပ တ ႔submit button က ပ လ က ရင form ထ က အ ခ က အလ က တ က welcome.php ဆ တ ႔file လ ဆ က ပ ႔ ပ တ ဖစ ပ တယ အခ တ ႔welcome.php မ ရ ရ သ တ ႔အတ က button က ပ လ က ရင object not found လ ႔ ပၚပ လ မ ႔မယ welcome.php ဖ င လ က ပ ရ လ က ပ မယ <html> <body> Welcome echo $_POST ["name"];.<br /> You are echo $_POST ["age"]; years old. </body> </html> ဒ လ က welcome.php လ ႔အမည ပ ပ ခ နက form1.html န ႔ နရ အတ တ folder တ စ ခ ထ ည မ save လ က မယ.. ပ ရင form1.html က လ ႔ ခၚ ပ run မယ အမည န ႔အသက က ထ ည ပ submit button ပ လ က ရင ဒ လ ပ စ မ output ရလ ပ လ မ ႔မယ Welcome You are 20 years old. PHP $_GET PHP $_GET variable က get method က သ ပ တ ႔form တစ ခ က တန ဖ တ က ရယ ဖ ႔အတ က အသ ပ ပ တ ယ $_GET variable က HTTP GET method က နပ ႔လ က တ ႔variable names တ န ႔တ န ဖ တ ရ ႕array တစ ခ ဖစ ပ တ ယ GET method က အသ ပ ပ အခ က အလက တ က ပ ႔တ ႔အခ မ (browser ရ ႕ address bar မ ပလ ႔ရ ရင ) လ တ င မင ရပ တယ ပ တ ႔အမ ဆ 100 characters ပ ပ ႔လ ႔ရတ ယ ဆ တ ႔ကန ႔သ န ႔ခ က ရ ပ တယ Example <form action ="welcome1.php" method ="get"> Name:<input type="text" name = "name1"/> Age: <input type= "text" name = "age1"/> <input type="submit"/> </form> ဒ code လ က form2.php လ ႔save လ က ပ တယ (က န က တ ႔စ အ ပ ရ ႕အစပ င မ ပ ခ ႔သ လ ပ php န ႔html file တ အ လ က C: အ က က xampp အ က က htdocs အ က က php ရ ႕ အ က ထ မ ပ save တ ဖစ ပ တ ယ ဒ မ လ ႔browser address bar မ ခၚ ပ run ရတ ဖစ ပ တ ယ ) welcome1.php ဆ တ ႔file က အ က ပ အတ င ရ ပ တ ႔save လ က ပ တယ Welcome echo $_GET["name1"];.<br /> 29 Youth Dreams 29

30 You are echo $_GET["age1"]; years old! အခ အခ န မ form2.php က run လ က တ ႔ပ တ ယ text box စ ခ က ဖည ပ တ ႔submit button ပ လ က တ ႔အ ခ address bar မ ဆ ပ တ ႔ ပၚသ တ တ ႔ရပ တယ.. welcome1.php ဖ င ထ မ name1 န ႔age1 ရ ႕တ န ဖ တ က $GET variable န ႔catch လ ပ ထ တ ႔အတ က browser မ အခ လ ပပ တ ယ Welcome moemyintshein. You are 20 years old! $_GET variable က အသ ပ တ ႔အခ variable name တ န ႔တန ဖ တ က address bar မ ပတ က ခ ရမ ဖစ တ ႔အတ က password တ န ႔ လ သ မခ စလ တ ႔ အခ က အလ က တ က ပ ႔ ပ တ ႔အခ မ မသ သင ပ ဘ ဒ ပမယ ႔ တခ ႕ နရ တ မ တ ႔အခ လ variable တ က URL မ မင ရတ ႔အတ က အက ရ ပ တယ အရမ ၾက တ ႔variable values တ က လည မက င တ ယ င ပ ဘ character အလ 100 ထ က ပ လ ႔မရလ ႔ပ THE $ REQUEST Variable $_REQUEST variable က $_GET, $_POST န ႔$_COOKIE တ ႔အလ ပ လ ပ သလ လ ပ ပ ပ တ ယ Get method န ႔ ဖစ ဖစ POST method န ႔ ဖစ ဖစ ပ ႔လ က တ ႔data တ ရ ႕result က ရရ စဖ ႔အတ က အသ ပ င ပ တယ အကယ လ ႔ခ နက welcome1.php ဖ င လ မ $_GET နရ မ $_REQUEST လ ႔ အ က ပ အတ င ပ င ရ ရင လ ည အတ တ ပ အလ ပ လ ပ တ ဖစ ပ တ ယ Welcome echo $_REQUEST["name1"];.<br /> You are echo $_REQUEST["age1"]; years old! PHP $_POST $_POST variable က တ ႔HTTP POST method က သ ပ variable name န ႔values တ ရ ႕array တ စ ခ ပ ဖစ ပ တ ယ method= post ဆ ပ တ ႔form တစ ခ က တ န ဖ တ က ရယ ဖ ႔အတ က သ ပ တ ယ POST method က အသ ပ ရင ပ ႔လ က တ ႔အခ က အလ က တ က browser address bar မ မ မင ရတ ႔အ ပင အက န ႔အသ န ႔မရ လည ပ ႔ င ပ တ ယ က န က တ ႔form3.php လ ႔save ပ တယ Example <form action="welcome2.php" method="post"> Enter your name: <input type="text" name="name" /> Enter your age: <input type="text" name="age" /> <input type="submit" /> </form> welcome2.php ရ ႕code မ POST က သ ပ လ က ခ ပ မယ Welcome echo $_POST["name"];.<br /> You are echo $_POST["age"]; years old! 30 Youth Dreams 30

31 form3.php က run ပ တ ႔အမည အသ က တ ႔က ဖည ပ submit လ ပ တ ႔အခ GET method န ႔မတ ပ address bar မ ဒ လ လ ပ ပ ပ ပ တ ယ output က တ ႔ အထက က GET method တ န ကလ ပ ဖစ မ ပ $_REQUEST Variable က $POST နရ မ ထည ပ သ ရင လည တ တ ပ ရမ ဖစ ပ တ ယ.. တ ခ တရ မ GET method က အသ ပ ပ တ ႔တခ တရ မ POST method က သ တ ကပ သ င လ ပ တ ယ 31 Youth Dreams 31

32 Chapter 5.PHP Date, Include & File Handling The PHP Date() Function အခ န န ႔ န႔ရက တ က ပ စ ခ ဖ ႔အတ က ဒ function က အသ ပ ပ တ ယ သ ႔ရ ႕Syntax က တ ႔ date(format, timestamp) ဖစ ပ တယ format ဆ တ ႔parameter က တ ႔မ ဖစ မ နပ ၀င ဖ ႔လ အပ ပ တ ယ အခ န ရ ႕ format က သက မ တ ပ တ ဖစ ပ တ ယ timestamp က တ ႔optional ပ default အ နန က တ ႔လက ရ န႔ရက န ႔ အခ န က timestamp အ နန ႔သ သ မ ဖစ ပ တ ယ timestamp ဆ တ က တ ႔1970 ဇန န၀ ရ တ စ ရက GMT 00:00:00 က နစတ ႔စက န ႔အ ရအတ က ဖစ ပ တ ယ Unix Timestamp လ ႔လည ခၚၾက ပ တယ date() function ရ ႕ပထ မ parameter ဖစ တ ႔format က date/time တစ ခ က ဘ ယ လ format ပ ရမလ ဆ တ သတ မ တ ပ ပ တ ယ န႔ရက န ႔အခ န ပ စ တ က က ယ စ ပ ပ ဖ ႔အတ က letter တ က အသ ပ ပ တ ယ အသ ပ င တ ႔ ပ စ တ က တ ႔ - d - လတ စ လရ ႕ရက တ ဖစ ပ တ ယ (01-31) - m - လ က ရ လ ဖစ ပ တ ယ (01-12) - Y digit လ လ န ႔ ရ တ ႔လ က ရ စ ပ ဖစ ပ တယ /,., - အစရ တ ႔character တ က လည letter တ ၾက ထ မ ထည သ င အသ ပ င ပ တယ echo date("y/m/d"); echo "<br />"; echo date("y.m.d"); echo "<br />"; echo date ("Y-m-d"); အထက ပ code က run လ က မယ ဆ ရင အ က ပ ပ စ အတ င output ရလ မ ပ ဖစ ပ တယ 2009/09/ date() function ထ မ format ဆ တ ႔ parameter တစ ခ ထ ပ ၀င တ ႔ ပ စ ဖစ ပ တ ယ timestamp အ နန ႔ အခ ရ က နတ ႔အခ န န ႔ န႔က အလ အ လ က ခၚသ သ တ ဖစ ပ တ ယ PHP Date- Adding a Timestamp date() function ထ က ဒ တ ယ parameter ဖစ တ ႔timestamp က ပ ထည ပ သ ၾကည ပ မယ အခ ထပ ပ ၾက ည ၾကမယ ႔ ဥပမ လ မ mktime () ဆ တ ႔function လ က သ ပ တ ႔မနက ဖန အတ က timestamp တစ ခ က ဖန တ ပ မယ mktime() function အ နန ႔specified date တစ ခ အတ က Unix timestamp က return ပန ပ ပ တယ သ ႕ရ ႕Syntax က တ ႔ mktime(hour, minute, second, month, day, year, is_dat) ဖစ ပ တယ အန ဂတ က မနက ဖန ဖစ တ ႔အတ က တစ ရက ပ ထ ပ ပ င ပ ရပ မယ mktime() function ရ ႕day ဆ တ ႔argument မ တ စ ရက ထ ပ ပ င ပ လ က ရ န ႔ မနက ဖန အခ န န ႔ န႔က ဖ ပမ ဖစ ပ တ ယ 32 Youth Dreams 32

33 $tomorrow = mktime(0,0,0,date("m"),date("d")+1, date("y")); echo "Tomorrow is ". date("y/m/d", $tomorrow); သ ႕ရ ႕output က တ ႔Tomorrow is 2009/09/14 ပ ဖစ ပ တယ ဒ န႔လ က ရ အခ န က စက တင ဘ 13 ဖစ တ ႔အတ က ဖစ ပ တ ယ PHP Include File Server Side Includes ဆ တ ႔SSI က စ မ က ပ င မ စ ပၚမ ထပ ခ ထပ ခ အသ ပ မယ ႔functions တ header တ footer တ elements တ က ဖန တ ဖ ႔အတ က အသ ပ ပ တယ Server Side Includes include() ဒ မ မဟ တ require() ဆ တ ႔function က သ ပ တ ႔PHP file တ စ ခ ထ က ဆ ဗ က မ run ခင မ file ရ ႕ content က ထ ည ပ င ပ တ ယ ဒ function စ ခ ရ ႕အလ ပ လ ပ ပ က နရ အ တ မ မ မ အတ တ ဖစ ပ တ ယ က သ တ က တ ႔include () function အ နန ႕က warning က ထ တ ပ မယ.. ဒ ပမယ ႔script က တ ႔ဆက ပ execute လ ပ သ မ ဖစ ပ တ ႔require () function က တ ႔error ထ တ ပ မယ ပ ရင script က လည ဆက ပ execute မလ ပ တ ႔ဘ ရပ လ က မ ဖစ ပ တယ ဒ function စ ခ က စ မ က တ အမ ၾက ပၚမ ထ ပ ခ ထ ပ ခ အသ ပ င တ ႔function တ header တ footer တ န ႔elements တ က ဖန တ ဖ ႔အသ ပ ၾက တ ဖစ ပ တ ယ ဒ လ လ ပ တ ဟ developer အတ က အခ န က န သ က သ စပ တယ ဆ လ တ က က န တ ႔ရ ႕ web page တ အ လ မ ပ ၀င စခ င တ ႔header ဒ မ မဟ တ menu file လ တစ ခ က ဖန တ င ပ တ ယ header က update လ ပ ဖ ႔လ အပ တ ႔အခ ဒ include file တ စ ခ ထ က ပ update လ ပ ဖ ႔လ မ ဖစ သလ site ထ က စ မ က အသ စ တ စ ခ ထ ပ ပ င တ ႔အခ မ မ လ ည web page တ အ လ ရ ႕link တ က update လ ပ ရမ ႔အစ menu file လ က ပ ပ င လ ပင ဆ င ပ ရ ပ ဖစ ပ တ ယ Example က န တ ႔မ header.php ဆ တ ႔header file တစ ခ ရ တယ လ ႔ယ ဆ ၾကည ပ မယ ဒ header file က page တစ ခ မ ပၚဖ ႔အတ က include() function က အ က ပ အတ င အသ ပ င ပ တယ <html> <body> include("header.php"); <h1> Welcome to my home page</h1> <p> Some text</p> </body> </html> Example 2 33 Youth Dreams 33

34 include file တ ဟ အမ အ ဖင.php န ႔ပ အဆ သ တ တ ဖစ ပ တ ယ အခ တ စ ခ web page တ အ လ မ အသ ပ မယ ႔menu file လ တ စ ခ ရ တယ လ ႔ယ ဆပ မယ အ က က menu.php က လ႔လ ၾကည ပ မယ <html> <body> <a href =" Home </a> <a href= " About Me</a> <a href=" Contact Me</a> </body> </html> default.php, about.php န ႔contact.php ဆ တ ႔file သ ခ စလ မ menu.php ဆ တ ႔file လ ပ ၀င သင ပ တ ယ ဥပမ ဒ က တ ႔default.php ထ က code ပ ဖစ ပ တ ယ <html> <body> include("menu.php"); <h1> Welcome to my home page</h1> <p> Some text</p> </body> </html> က န တ ႔menu.php က ပ run တ ႔အခ output အ နန ႔ Home About Us Contact Us ဆ ပ တ ႔ရလ မ ဖစ ပ တ ယ default.php က run တ ႔အခ မ တ ႔ Home About Us Contact Us Welcome to my home page Some text ယခ လ ပ ပၚမ ဖစ ပ တ ယ default.php န ႕menu.php က တ ႔directory(folder) တစ ခ ထ မ ပ ရ ရပ မယ အကယ က န တ ႔က about.php က အ က ပ အတ င ရ မယ ဆ ရင <html> <body> include("menu.php"); <h1> Welcome to my about me page.</h1> <p> Some text</p> </body> </html> 34 Youth Dreams 34

35 အ က ပ အတ င Output ရမ ဖစ ပ တယ Home About Us Contact Us Welcome to my about me page. Some text သ ႔ရ ႕source က ၾက ည မယ ဆ ရင လည <html> <body> <html> <body> <a href=" <a href=" Us</a> <a href=" Us</a><h1> Welcome to my about me page.</h1> <p> Some text</p> </body> </html> အခ လ ပ တ ႕ရမ ဖစ ပ တ ယ က န တ ႔အ နန ႔ contact.php မ လည အခ လ ပ include.php က ပန ခၚ ပ ရ င တ ဖစ ပ တယ include file က အသ ပ ခင အ ဖင menu link တ ရ အစ အစဥ က ပ င လ ခ င တ ႔အခ အမည ပ င ခ င တ ႔အခ ဒ မ မဟ တ site ထ က န က ထ ပ web page ထ ပ ထည ခ င တ ႔အခ တ မ မ page တ စ ခ စ file တစ ခ စ မ ပင ဖ ႔မလ ဘ န ႔menu.php ထ မ ရ တ ႔code က ပ ပင လ က ရ ပ ဖစ ပ တ ယ The require() Function require () function က include() function အလ ပ လ ပ သ လ ပ ပ စ တ အလ ပ လ ပ ပ တ ယ error က က င တ ယ တ ႔ နရ မ ပ က ခ မ ရ တ ဖစ ပ တယ include() function က သ ရင warning ပ ရ သ ပ ပ script က ဆ က run မ ဖစ ပမယ ႔require() function က သ ထ ရင တ ႔error message ပ ပ တ န ႔ဆက ပ တ ႔လ ည execute လ ပ မ မဟ တ တ ႔ပ ဘ include() function န ႔ဖ င တ စ ခ က ခၚသ ထ ပ အ ဒ ဖ င က ရ မ တ ႔ရင သ လ ည က င error တစ ခ ခ ဖစ တ ယ ဆ ရင အ က ပ အတ င error message တတ မ ဖစ ပ တယ PHP CODE <html> <body> include("wrongfile.php"); 35 Youth Dreams 35

36 echo "Hello World!"; </body> </html> ERROR MESSAGE Warning: include(wrongfile.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\php\10.php on line 5 Warning: include() [function.include]: Failed opening 'wrongfile.php' for inclusion (include_path='.;c:\xampp\php\pear\') in C:\xampp\htdocs\php\10.php on line 5 Hello World! error message ဘ ယ လ ပ ပ ပ echo ၾက င ရလ တ ႔Hello World က တ ႔ execute လ ပ တ ပ ဖစ ပ တယ ဒ ဟ include က သ တ ႔အတ က warning ပ ရ ပ ရ ပ execute လ ပ တ က မရပ လ က တ ႔အတ က ဖစ ပ တယ အခ ဒ ဥပမ က ပ require() function န ႔ ပ င ပ ရ ၾက ည ပ မယ PHP CODE <html> <body> require("wrongfile.php"); echo "Hello World!"; </body> </html> Error Message Warning: require(wrongfile.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\php\10.php on line 5 Fatal error: require() [ function.require]: Failed opening required 'wrongfile.php' (include_path='.;c:\xampp\php\pear\') in C:\xampp\htdocs\php\10.php on line 5 36 Youth Dreams 36

37 echo statement က တ င execute မလ ပ ပ ဘ require က သ ထ တ ႔ ဖစ ပ တ ယ error ပ ပ တ န ႔execute လ ပ တ က ပ ရပ လ က တ ဖစ ပ တယ က န တ ႔တ ကယ ရ တ ႔အခ မ တ ႔include() က သ မယ ႔အစ require() က သ ဖ ႔recommend လ ပ ပ တယ အက ယ file တ missing ဖစ နတ မ န မည မ နတ မ ဖစ တ ႔အခ မ script က ဆ က လ က ပ execute မလ ပ စသင တ ႔အတ က ဖစ ပ တ ယ PHP File Handling Opening a File PHP မ fopen() function က file တ က ဖ င ဖ ႔အတ က အသ ပ ၾကပ တယ function ရ ႕ ပထ မ parameter မ ဖ င မယ ႔ဖ င ရ ႕ အမည ပ ၀င မ ဖစ ပ.. ဒ တ ယ parameter မ တ ႔ဘ ယ လ ပ စ မ န ႔ဖ င က ဖ င ခ င မယ ဆ တ သတ မ တ ပ ရမ ဖစ ပ တယ <html> <body> $file=fopen("welcome.txt","r"); </body> </html> file က ဘ ယ လ ပ စ မ န ႔ဖ င ခ င မယ ဆ တ ႔ဒ တ ယ parameter မ ရ ရတ ႔mode ပ င မ စ ရ ပ တ ယ အခ က န သ လ က တ ႔r က တ ႔read only က ဆ လ တ ပ အ က က ဥပမ မ အက ယ welcome.txt ဆ တ ႔file က သ ႔ရ ႕directory မ ရ မ နဘ ဆ ရင fopen() function အလ ပ မလ ပ ပ န ႔Unable to Open File! ဆ တ ႔error message က ပ ပ မ ဖစ ပ တယ <html> <body> $file=fopen("welcome.txt","r") or exit("unable to open file!"); </body> </html> Closing a File fcolse() function က တ ႔ဖ င ထ တ ႔ဖ င က ပ တ ဖ ႔အတ က သ တ ပ ပ ႔.. 37 Youth Dreams 37

38 $file = fopen("welcome2.txt","r"); //some code to be executed fclose($file); Checking End-of-File feof() function က သ ပ တ ႔ဖ င ရ ႕အဆ (End of File) ရ က ပ လ ဆ တ က စစ င ပ တယ ဒ function က ဘယ လ က data length ရ တ ယ ဆ တ က မသ တ ႔looping တ အတ က အသ ၀င ပ တယ if (feof($file)) echo End of file ; Reading a File Line by Line fgets() function က သ ပ တ ႔ဖ င တစ ခ က တ စ ၾက င ခင က read လ ပ ဖ ႔သ ပ တယ အ က က ဥပမ မ တစ ၾက င ပ တ စ ၾက င ဖ င ရ ႕အဆ က မ ရ က မခ င read လ ပ သ တ ဖစ ပ တယ အကယ fopen() function က file က မဖ င င ဘ ဆ ရင false(0) က return ပန မ ဖစ ပ တ ယ $file = fopen("welcome.txt", "r") or exit("unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)) echo fgets($file). "<br />"; fclose($file); ဒ ဟ က run လ က တ ႔အခ welcome.txt ထ ကစ တ တ စ ၾက င ပ တစ ၾက င က read သ ပ တ ႔echo န ႔ ပထ တ ဖစ တ ႔အတ က browser မ welcome.txt ဖ င ထ က စ တ အက န လ ပၚမ ဖစ ပ တယ Reading a File Character by Character fgetc() function က တ ႔ဖ င တစ ခ က character တစ လ ခ င စ က read လ ပ ဖ ႔သ ပ တယ အ က က ဥပမ လ က ဖ င ရ ႕ အဆ က ရ က သ တ ႔အထ character တ စ လ ခ င စ က read လ ပ သ တ ပ ဖစ ပ တ ယ $file=fopen("welcome.txt","r") or exit("unable to open file!"); while (!feof($file)) echo fgetc($file); fclose($file); 38 Youth Dreams 38

39 PHP File Upload အခ က န တ ႔PHP က သ ပ တ ႔server ပၚက file တ upload တ င တ က ၾကည ပ မယ user တ အ နန ႔ဖ င တ က upload တ င င ဖ ႔အတ က form က သ မယ ဆ ရင အဆင ပပ တယ အ က က HTML code က ဖ င တ upload တ င တ ႔ နရ မ သ င ပ တယ <html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">filename:</label> <input type="file" name="file" id="file"/> <br/> <input type="submit" name="submit" value="submit" /> </form> သ ႔က run လ က မယ ဆ ရင browser မ အ က ကအတ င browse လ ပ ဖ ႔ရယ submit လ ပ ဖ ႔ရယ အတ က upload တင တ ႔ ပ စ လ က ရပ ပ.. ဒ form မ က န တ ႔submit button က ပ လ က မယ ဆ ရင upload_file.php ဆ တ လ က run မ ဖစ ပ တ ယ upload_file.php ဖ င လ က အ က ပ အတ င ရ ပ သ မ လ က ပ မယ if ($_FILES["file"]["error"] > 0) echo "Error: ". $_FILES["file"]["error"]. "<br />"; else echo "Upload: ". $_FILES["file"]["name"]. "<br />"; echo "Type: ". $_FILES["file"]["type"]. "<br />"; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb<br />"; 39 Youth Dreams 39

40 echo "Stored in: ". $_FILES["file"]["tmp_name"]; PHP $_FILES array က သ ပ တ ႔remote server ဆ က client computer က နဖ င တ တင တ ပ ဖစ ပ တယ ပထမဆ parameter က တ ႔ ဖ င ရ ႕input name ဖစ ပ တ ယ.. ဒ တ ယ index အ နန ႕က တ ႔name, type, size, tmp_name, error စသ ည ဖင တစ ခ ခ ဖစ င ပ တ ယ - $_FILES[ file ][ name]- upload တ င လ က တ ႔ဖ င ရ ႕အမည - $_FILES[ file ][ type ]- upload တင လ က တ ႔ဖ င ရ ႕အမ အစ - $_FILES[ file ][ size ]- upload တ င လ က တ ႔ဖ င ရ ႕size (bytes န ႔ ပ ပ ပ တယ ) - $_FILES[ file ][ tmp_name ]- server မ သ မ မယ ႔ဖ င ရ ႕ယ ယ က ပ ရ ႕န မည - $_FILES[ file ][ error ]- ဖ င upload လ ပ ရက န ဖစ လ င တ ႔error code စသည ဖင ဖစ ပ တယ အခ ဒ ပ စ က ဖ င က php န ႔အရ ရ င ဆ upload တင တ ႔ပ စ ပ ဖစ ပ တယ security အတ က user တ က ဖ င upload တင ခ င ပ တ ႔အခ မ ကန ႔သ န ႔ခ က တ ထ ရ သင ပ တယ Restrictions on Upload အခ အ က က script ထ မ ဖ င upload လ ပ တ ႔ နရ မ က န ႔သတ ခ က အခ ႕ထ ည ပ မ ဖစ ပ တယ user အ နန ႔gif ဒ မ မဟ တ jpeg ဖ င တ က ပ upload ခ င ပ ပ မယ ဖ င အရ ယ အစ က လ ည 20 kb ထက မၾက စရဘ လ ႔ ကန ႔သတ ပ မယ if ((($_FILES["file"]["type"] == "image/gif") ($_FILES["file"]["type"] == "image/jpeg") ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) if ($_FILES["file"]["error"] > 0) echo "Error: ". $_FILES["file"]["error"]. "<br />"; else echo "Upload: ". $_FILES["file"]["name"]. "<br />"; echo "Type: ". $_FILES["file"]["type"]. "<br />"; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb<br />"; echo "Stored in: ". $_FILES["file"]["tmp_name"]; else 40 Youth Dreams 40

41 echo "Invalid file"; Saving the uploaded File အ ပၚက ဥပမ က server မ ရ တ ႔PHP temp folder ထ မ ပ upload တ င လ က တ ႔ဖ င ရ ႕ ယ ယ က ပ က ပ ဖန တ ပ တ ဖစ ပ တယ php script ဆ သ တ န ႔အ ဒ က ပ က လည ပ က သ မ ဖစ ပ တယ upload လ ပ လ က တ ႔ ဖ င က store လ ပ ဖ ႔အတ က location တ စ ခ က က ယ ပ ဖ ႔လ အပ ပ တယ if ((($_FILES["file"]["type"] == "image/gif") ($_FILES["file"]["type"] == "image/jpeg") ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) if ($_FILES["file"]["error"] > 0) echo "Return Code: ". $_FILES["file"]["error"]. "<br />"; else echo "Upload: ". $_FILES["file"]["name"]. "<br />"; echo "Type: ". $_FILES["file"]["type"]. "<br />"; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb<br />"; echo "Temp file: ". $_FILES["file"]["tmp_name"]. "<br />"; if (file_exists("upload/". $_FILES["file"]["name"])) echo $_FILES["file"]["name"]. " already exists. "; else move_uploaded_file($_files["file"]["tmp_name"], "upload/". $_FILES["file"]["name"]); echo "Stored in: ". "upload/". $_FILES["file"]["name"]; else 41 Youth Dreams 41

42 echo "Invalid file"; upload_file.php ဖ င လ က အထ က ပ code အတ င ရ ပ သ မ လ က တ ႔အခ upload.php က run လ ႔ရပ ပ php directory (C:\xampp\htdocs\php) အ က မ upload ဆ တ ႔folder လ က ဆ က ပ လ က ပ.. အ ဒ န က upload တင မယ ဆ ရင တ ႔upload ဆ တ ႔folder အ က ထ က က ယ တင လ က တ ႔file လ ရ က နမ ဖစ ပ တယ အခ က က န တ ႔က က ယ ႔ရ ႕local စက ထ မ ပ စမ နတ ဖစ ပ တ ယ web hosting ပၚမ စမ ရင လ ည သ ဘ တ ရ က တ ႔ အတ တ ပ ဖစ ပ တ ယ PHP Cookies cookie က user တ စ ယ က ရ ႕identity အတ က အသ ပ ပ တယ cookie ဆ တ user ရ ႕က န ပ တ ပၚမ ဆ ဗ က န ခ န ထ ခ ႔တ ႔ဖ င လ တ စ ခ ပ ဖစ ပ တ ယ browser တစ ခ က သ ပ တ ည တ ႔က န ပ တ တ စ လ က န web page တစ ခ က request လ ပ လ က တ ႔အခ တ င မ cookie က ပ ႔ ပ ပ တ ယ PHP က သ ပ တ ႔ cookie ဖန တ ပ ရယ ပ တ က လ႔လ ၾက ပ မယ How to Create a Cookie? cookie တ စ ခ က ဖန တ ဖ ႔အ တ က setcookie() function က သ ပ တယ setcookie() function က <html> tag ရ ႕အ ရ ႕မ ရ ရမ ဖစ ပ တ ယ setcookie (name,value,expire,path,domain); ဒ က တ ႔cookie က set လ ပ တ ႔syntax ဖစ ပ တယ Example အ က က ဥပမ လ မ က န တ ႔user ဆ တ ႔cookie လ တ စ ခ က ဖန တ ပ တယ Alex Porter ဆ တ ႔တ န ဖ က ပ ပ တ ယ တစ န ရ ၾက တ ႔အခ expire ဖစ ဖ ႔က သက မ တ ပ ပ တ ယ setcookie("user", "Alex Porter", time()+3600); <html>... cookie ရ ႕expire time က န က ထ ပ နည တစ မ န ႔အခ လ သက မ တ င ပ တ ယ စက န ႔က သ တ ထ က ပ လ ယ ပ တယ $expire=to,e()+60*60*24*30; setcookie("user", "Alex Porter", $expire); <html>... ဒ ဥပမ မ ဆ ရင expire time က တ စ လ အ ဖစ သ တ မ တ ထ ခ ႔တ ဖစ ပ တ ယ (60 sec * 60 min * 24 hours * 30 days). 42 Youth Dreams 42

43 Cookie တန ဖ တ စ ခ က Retrieve လ ပ ခင //Print a cookie echo $_COOKIE["user"]; // A way to view all cookies print_r($_cookie); ဒ ဥပမ မ user ဆ တ ႔cookie လ ရ ႕တ န ဖ က ရယ ပ တ ႔ ပန ပ ပ ပ တယ အ က က ဥပမ မ တ ႔ isset() function က သ ပ cookie တ စ ခ ဟ တန ဖ သတ မ တ လ က ခင ရ မရ က စစ ဆ မ ဖစ ပ တယ <html> <body> if (isset($_cookie["user"])) echo "Welcome". $_COOKIE["user"]. "!<br/>"; else echo "Welcome guest!<br />"; </body> </html> Cookie တစ ခ က ဖ က ပစ ခင cookie တစ ခ က ဖ က ပစ တ ႔အခ မ expiration date က အတ တ မ က န ခ ႔တ သ ခ စဖ ႔သ င ပ တ ယ ဥပမ //set the expiration date to one hour ago setcookie("user", "", time()-3600); Browser တစ ခ က Cookie က support မလ ပ တ ႔အခ အ ခ နည လမ တ က အသ ပ ပ စ မ က တ စ ခ က နတစ ခ က အခ က အလ က တ က ပ ႔ ပ ဖ ႔လ ပ ရပ တယ နည လမ တစ ခ က တ ႔form က အသ ပ ခင ဖစ ပ တယ အ က ကဥပမ လ မ Submit button က user က ပ လ က တ ႔အခ welcome.php ဆ က user input တ က လ မ ပ ႔ ပ တ ဖစ ပ တ ယ <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name"/> 43 Youth Dreams 43

44 Age : <input type="text" name ="age"/> <input type="submit"/> </form> </body> </html> အထက ပ code တ က form1.php လ ႔save လ က တယ ဆ ပ စ ႔ welcome.php ဖ င ထ မ အ က ပ အတ င တန ဖ တ က retrieve လ ပ ယ ရမ ဖစ ပ တ ယ <html> <body> Welcome echo $_POST["name"];. <br /> You are echo $_POST["age"]; years old. </body> </html> အထက ပ ဥပမ မ forum1.php က Browser မ run လ က တ ႔အခ အမည န ႔အသ က က ဖည ဖ ႔text box စ ခ ရ မ ဖစ ပ တ ယ ဖည ပ တ ႔submit က ပ လ က ရင အ က ပ အတ င ဖည လ က တ ႔အ ပၚမ မ တ ည ပ ပန ပ ပ ပ လ မ ႔မယ က န က တ ႔အမည မ moemyintshein အသက မ 20 က ထ ည ပ submit လ ပ လ က တ ႔အခ Welcome moemyintshein. You are 20 years old. PHP Sessions PHP session variable တ စ ခ က user session တစ ခ အတ က အခ က အလက တ က သ မ ဆ ည ဖ ႔ သ လ ည က င ဆက တင တ က ပ င လ ဖ ႔ရန သ လည က င အသ ပ ရပ တယ user တ စ ယ က ရ ႕ အခ က အလက တ က က င တ ယ ပ တ ႔application တစ ခ ရ ႕စ မ က တ အ လ မ ပန သ င ပ တယ application တ စ ခ က သ တ ႔အခ မ က န တ ႔က အ ဒ က ဖ င တ ယ အ ပ င အလ အခ ႕က လ ပ တ ယ.. ပ ရင ပ တ လ က တ ယ. ဒ ဟ session ပ ပ computer က က န တ ႔ဘယ သ ဆ တ က သ တ ယ က န တ ႔ ဘယ အခ န မ ဒ က စဖ င ပ တ ႔ ဘယ အခ န မ ပ တ လ က တ ယ ဆ တ က သ က သ ပ တယ အင တ နတ ပၚမ ဆ ရင တ ႔ ပသန တစ ခ ရ လ ပ တယ web server က တ ႔ က န တ ႔ဘ ယ သ ဆ တ ဘ တ လ ပ တ ယ ဆ တ က မသ င ပ ဘ.. ဘ လ ႔လ ည ဆ တ ႔HTTP အ နန ႔state က maintain မလ ပ ပ ပ ဘ ဒ ပသ န က PHP session က သ ပ တ ႔ ဖရ င ပ တ ယ သ ႕က သ ပ တ ႔ န င အခ မ ပန လ ည အသ ပ တ ႔အခ remember ဖစ န စဖ ႔အတ က user ရ ႕႔အခ က အလက တ က server ပၚမ သ မ ဆ ည ထ င ပ တယ ဒ ပမယ ႔ session information တ က ယ ယ ပ ဖစ ပ တယ user က website က န ပန လ ည ထ က ခ သ တ န ႔ ပ က သ မ ဖစ ပ တ ယ အကယ အ မ တမ ရ န စခ င တ ယ ဆ ရင တ ႔ database ထ မ data တ က သ မ ရမ ဖစ ပ တယ session အ နန ႔unique id( UID) တ စ ခ က visitor တစ ဥ စ တ င အတ က ဖန တ ပ ပ တ ယ ပ တ ႔အခ ဒ UID ပၚမ အ ခခ ပ တ ႔ variable တ က သ မ ဆည ပ တယ UID က တ ႔ cookie တစ ခ ထ မ သ လ ည က င URL ထ မ propagated လ ပ ပ သ လ ည က င သ မ ဆည ပ တယ Starting a PHP Session 44 Youth Dreams 44

45 PHP session တ စ ခ ထ မ user information တ က မသ မ ခင အရင session တ စ ခ က အစ ပ ပ ရပ မယ session_start() function က <html> tag မလ ခင မ ရ ရပ တယ session_start(); <html> <body> </body> </html> အခ လ အတ င ရ ပ လ က ခ ႔မယ ဆ ရင server ပၚမ user session က register လ ပ လ က ပ တ ႔user Information တ စတ င သ မ မ ဖစ ပ တယ ဒ ႔အ ပင user session အတ က UID တစ ခ က လည assign လ ပ ပ ပ တ ယ Storing a Session Variable session variable တ က သ မ ဖ ႔ထ တ ယ ဖ ႔အတ က သ ရတ က တ ႔PHP $_SESSION variable ပ ဖစ ပ တယ session_start(); //store session data $_SESSION['views']=1; <html> <body> //retrieve session data echo "Pageviews=". $_SESSION['views']; </body> </html> output အ နန ႔Pageviews=1 ဆ ပ ရမ ဖစ ပ တ ယ အခ ထ ပ ပမယ ႔ဥပမ မ တ ႔ရ ရ င တ ႔page view counter တစ ခ က ဖန တ မ ဖစ ပ တယ isset() function က သ ပ တ ႔views ဆ တ ႔variable က သတ မ တ ထ မထ စစ ပ မယ.. သတ မ တ ထ ပ သ ဆ ရင counter က တစ တ ပ မယ မဖန တ ရ သ ဘ ဆ ရင တ ႔views variable က ဖန တ ပ တ ႔တ န ဖ က တစ လ ႔သတ မ တ ပ ပ မယ session_start(); if(isset($_session['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; 45 Youth Dreams 45

46 echo "Views=". $_SESSION['views']; ဒ က run ၾက ည မယ ဆ ရင. relode လ ပ လ က တ ႔အခ တ င မ views က တစ တ တ သ တ တ ႔မ ဖစ ပ တ ယ Destroying a Session session data က ပန ဖ က မယ ဆ ရင တ ႔ unset() function ဒ မ မဟ တ sessopm_destroy() function က အသ ပ င ပ တယ unset() function က တ ႔ ဖ ပထ တ ႔session variable က free လ ပ ပစ ဖ ႔အတ က အသ ပ ပ တယ unset($_session['views']); session_destroy()function က ခၚ ပ တ ႔session က လ ၀ဖ က ဆ လ ႔လ ည ရပ တ ယ session_destroy(); PHP Mail Function PHP script ရ ပ အ မ တ က တ က ရ က ပ ႔လ ႔ရပ တယ PHP ရ ႕mail() function က အသ ပ ရမ ဖစ ပ တယ Syntax mail(to,subject,message,headers,parameters) အ က က တ ႔သ ႔မ ထ ည လ ႔ရတ ႔parameter တ န ႔သ တ ႔ရ ႕ ဖ ပခ က တ ဖစ ပ တယ to, subject, message သ ခ က တ ႔မ ဖစ မ နထ ည ပ ရမ ဖစ ပ headers န ႔parameters တ က တ ႔Optional ပ ဖစ ပ တ ယ PHP Simple 46 Youth Dreams 46

47 PHP န ႔အ မ ပ ႔မယ ဆ ရင အရ င ဆ န ႔အလ ယ ဆ က တ ႔text စ သ တ က ပ ႔တ ပ ဖစ ပ တယ အ က က ဥပမ လ မ အရင ဆ $to, $subject, $message, $from, $headers စတ ႔variable တ က ၾက င ပ တ ႔ mail() function ထ မ အ မ တစ ခ က ပ ႔ဖ ႔အတ က ခၚသ တ ဖစ ပ တယ $to= $subject="test mail"; $message="hello! This is a simple message."; $from= "gtalk@moemyintshein"; $headers="from: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; PHP Mail Form PHP က သ ပ တ ႔က န တ ႔ရ ႕website တ ပၚမ feedback-form လ မ ဖန တ င ပ တယ အ က က ဥပမ မ form က သ ပ အ မ ပ ႔တ က ပထ တ ဖစ ပ တယ <html> <body> if (isset($_request[' '])) //if " " is filled out, send //send $ = $_REQUEST[' '] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "someone@example.com", "Subject: $subject", $message, "From: $ " ); echo "Thank you for using our mail form"; else //if " " is not filled out, display the form echo "<form method='post' action='mailform.php'> <input name=' ' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> 47 Youth Dreams 47

48 <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; </body> </html> code တ က save လ ပ တ ႔အခ mailform.php လ ႔save လ ပ လ က ပ တ ယ သ ႔ရ ႕အလ ပ လ ပ ပ က တ ႔ပထမဆ ရ ႕ input field က ဖည ထ မထ စစ ပ တ ယ မ ဖည ထ သ ဘ ဆ ရင တ ႔ ဆ လ တ က ပထ မဆ အၾက မ ဒ စ မ က က ရ က လ တ ဆ ရင တ ႔HTML form လ က ပ ပ ပ တယ အက ယ ဖည ပ သ ဖစ န ပ ဆ ရင တ ႔ form က နအ မ က ပ ႔ ပ ပ တယ submit buttion က ပ လ က တ န ႔ဒ page က ပ reload လ ပ ပ တ ယ input field မ ဖည ထ ပ ဖစ တ ႔အတ က အ မ က ပ ႔ ပ ပ တ ယ အ မ ပ ႔တ တ ဖစ တ ႔အတ က SMTP န ႔ smtp_post စတ ႔ ဆက တင တ က php.ini file မ သ တ မ တ တ တ.. လ ပ ရမ ဖစ ပ တယ အခ တ ႔အ ခခ ဖစ လ ႔သ ဘ တ ရ က န လည ရင ရပ ပ.. အ သ စ တ က က ယ တ င ဆက လ႔လ သ င ပ တ ယ အထက မ ဖ ပခ ႔တ တ က တ ႔အရ င ဆ အ မ ပ ႔တ ပ စ ပ ဖစ ပ တ ယ ဒ ပမယ ႔တက ယ တ မ တ ႔လ က တ ႔ လ ပ ရတ ႔အခ အခ အတ င ရ လ ႔မ ဖစ ပ ဘ.. အ ဒ က လ ခ မ မရ ပ ဘ ရ ႕အခန မ က န တ ႔ ပ ပ security က င အ င ရ ၾက ပ မယ PHP Secure s PHP Injections 48 Youth Dreams 48

49 အထက ကအခန မ က န တ ႔ ဖ ပခ ႔တ ႔code ရ ႕အ နည ခ က က တ ႔unauthorized user တ က input form ရ ႕mail header ထ မ data တ က ထည သ င င ပ တ ယ ဥပမ အ က မ ပထ သလ မ user က form ရ ႕input fileld ထ မ ထည မယ ဆ ရင အ ဒ လ ပ စ တ အက န လ ဆ က အ မ ရ က မ ဖစ ပ တ ယ အ က ပ code က form ထ က field က စစ ဆ ဖ ႔အတ က input က validate လ ပ ဖ ႔ပ ရ ထ တ ဖစ ပ တယ <html> <body> function spamcheck($field) //filter_var() sanitizes the //address using FILTER_SANITIZE_ $field=filter_var($field, FILTER_SANITIZE_ ); //filter_var() validates the //address using FILTER_VALIDATE_ if(filter_var($field, FILTER_VALIDATE_ )) return TRUE; else return FALSE; if (isset($_request[' '])) //if " " is filled out, proceed //check if the address is invalid $mailcheck = spamcheck($_request[' ']); if ($mailcheck==false) echo "Invalid input"; 49 Youth Dreams 49

50 else //send $ = $_REQUEST[' '] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@example.com", "Subject: $subject", $message, "From: $ " ); echo "Thank you for using our mail form"; else //if " " is not filled out, display the form echo "<form method='post' action='mailform.php'> <input name=' ' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; </body> </html> ဒ code မ က န တ ႔PHP Filter က အသ ပ ထ ပ တ ယ input က မ န မမ န စစ ဆ ဖ ႔ ဖစ ပ တ ယ - The FILTER_SANITIZE_ filter က string တစ ခ က illegal character တ အ လ က ဖယ ရ ပ ပ တ ယ - The FILTER_VALIDATE_ က တ ႔ လ ပ စ ရ ႕ အရည အခ င format က က မက က က စစ ဆ ပ ပ တ ယ PHP Filter အခန မ filter အ ၾက င ပ ရ သ ပ မယ PHP Error Handling PHP ရ ႕default error handling က တ ႔ရ ရ လ ပ ပ ဖ င ရ ႕န မည လ င န ပ တ ပ တ ႔error message န ႔ဘ error ဆ တ ပ ပ တ ႔browser က ပ ႔ ပ လ က တ ပ ပ web application တ ရ တ ႔အခ error handling ကအ ရ ၾက တ ႔ အပ င ပ ပ က န တ ႔ ရ လ က တ ႔code မ error checking code မပ ဘ ဆ ရင က န တ ႔ရ ႕ပရ ဂရမ က ပ ရ ဖက ရ င နယ မဆ န ပ ဘ ပ တ ႔security risk တ လည ရ လ ပ မယ ဒ အခန မ တ ႔PHP ရ ႕ error စစ တ ႔နည လ ည အခ ႕က ရ ပ မယ အ က ပ နည လ မ တ ပ ၀င ပ မယ - Simple die() statements 50 Youth Dreams 50

51 - Custom errors and error triggers - Error reporting Basic Error Handling: Using the die() function ပထ မဆ ဥပမ အ နန ႔text file တ စ ခ က ဖ င တ ႔ရ ရ င တ ႔code လ ပ.. အကယ ဖ င ရ ရင ဘ error မ ပၚမ မဟ တ ပ ဘ ဖ င မရ ခ ႔ရင တ ႔က န ႔ဆ မ တ ႔အခ အတ င ပၚပ တ ယ Warning: fopen(welcome.txt) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\php\20.php on line 2 ဒ လ မ error message မ က user က မရရ စခ င တ ႔အတ က.. အရင ဆ code ထ မ ဖ င ရ မရ အရင စစ ခ င မယ ပ မ access လ ပ ခ င ပ မယ if(!file_exists("welcome.txt")) die("file not found"); else #file=fopen("welcome.txt"."r"); အခ လ ရ လ က တ ႔အတ က welcome.txt ဖ င သ ရ မ နဘ ဆ ရင File not found ဆ တ ႔error message ပ ပၚမ ဖစ ပ တ ယ ပထ မcode ထ က စ ရင တ ႔အမ ၾက ပ ပ ရ ဖက ရ င နယ ဆ န သ တယ ပ ႔.. error က ပ ပ တ န ႔က န တ ႔ code တ က ဆ က မ run တ ႔တ ႔ရ ရ င တ ႔error handling တ စ ခ က သ ခ ႔တ ပ ဒ ပမယ ႔အ မ တမ ဒ ပ စ ၾက ပ သ လ ႔ တ ႔မ ဖစ ပ ဘ.. တ ခ error handling အတ က php function တ စ ခ ႕က ဆက လ ႔လ ၾကပ မယ Creating a Custom Error Handler ဒ ဟ လည ရ ရ င ပ တယ error တ စ ခ ဖစ တ ႔အခ မ function တစ ခ က ခၚဖ ႔အတ က လ ပ ပ ရတ ပ ပ ဒ function အ နန ႔အနည ဆ တ ႔parameters စ ခ ( error level န ႔error message) က က င တ ယ င ရပ မယ ဒ ပမယ ႔သ ႔အ နန ႔parameter င လ အထ လက ခ င တ ဖစ ပ တယ (optional: file, line number, error context) Syntax error_function (error_level, error_message, error_file, error_line, error_context) 51 Youth Dreams 51

52 Error Report Levels user က သတ မ တ တ ႔error handler တ က အသ ပ င တ ႔error အမ အစ တ ရ ႕error report levels တ ဖစ ပ တယ န မလည လ ႔အရမ စ တ မညစ နပ န ႔ဥ.. အ အ ဆ ဆ ပ ႔ န ဒ တ ရ တယ လ ႔ တ ႔သ သ တ ပ ႔ အခ က န တ ႔error တ က က င တ ယ ဖ ႔အတ က function တစ ခ က ဖန တ ပ မယ function customerror($errno, $errstr) echo "<b>error:</b> [$errno] $errstr<br />"; echo "Ending Script"; die(); ဒ code လ က တ ႔ရ ရ င တ ႔error handling function တစ ခ ပ ဖစ ပ တယ အ ဒ လ က စrun တ ႔အခ မ error level န ႔error message က ရယ ပ တ ႔output ပ ပ ပ တ ႔script က အဆ သ တ တ ပ ဖစ ပ တယ က န တ ႔error handling function က ဖန တ ပ ပ ဆ ရင ဘ ယ အခ န မ trigger လ ပ မယ (စ run မယ ) ဆ တ က ဆ ဖတ ရပ မယ Set Error Handler PHP ရ ႕default error handler က တ ႔built in error handler ပ ပ အ ပၚမ ရ ခ ႔တ ႔function က default error handler အ နန ႔script အ တ အတ င မ ထ ပ မယ တက ယ တ ႔error တ စ ခ ႕အတ က ပ ဒ error handler က သ ဖ ႔ 52 Youth Dreams 52

53 သတ မ တ ပ င ပ တယ ဒ လ နည န ႔မတ ည တ ႔error တ က မတ ည တ ႔နည လ မ တ န ႔က င တ ယ ဖရ င င တ ဖစ ပ တ ယ ဒ ဥပမ မ တ ႔error တ အ လ အတ က က န တ ႔ရ ႕error handler က သ ပ မယ set_error_handler( customerror ); error တ အ လ က က င တ ယ ဖ ႔က န တ ႔ရ ႕ function က သ မ ဖစ လ ႔set_error_handler() function အ နန ႔ parameter တ စ လ ပ လ အပ ပ တယ ဒ တ ယ parameter က တ ႔ error level က သတ မ တ ပ ဖ ႔အတ က ထပ ပ င ထည င ပ တယ အ က က ဥပမ လ မ တ ႔မရ တ ႔variable က Output ပ ပ ဖ ႔ၾက စ မ ဖစ ပ တယ က န တ ႔ရ ႕error handler က စမ ၾကည ၾက တ ပ ႔ //error handler function function customerror($errno, $errstr) echo "<b>error:</b> [$errno] $errstr"; //set error handler set_error_handler("customerror"); //trigger error echo($test); သ ႔က run မယ ဆ ရင - Error: [8] Undefined variable: test ဆ ပ တ ႔output ရမ ပ Trigger an Error user က data တ က input ပ င တ ႔script တ စ ခ မ illegal input တ ႔တ ႔အခ မ errors တ က trigger လ ပ ဖ ႔အသ ၀င ပ တယ PHP မ တ ႔trigger_error() function က သ ပ လ ပ ဆ င င ပ တ ယ အ က က ဥပမ မ တ ႔test varuable က 1 ထ က ၾက မယ ဆ ရင error တစ ခ ဖစ မ ဖစ ပ တယ $test=2; if ($test>1) trigger_error("value must be 1 or below"); သ ႔က run တ ႔အခ မ က န က တ ႔ အ က ပ အတ င output ရပ တ ယ Notice: Value must be 1 or below in C:\xampp\htdocs\php\30.php on line 5 53 Youth Dreams 53

54 Chapter 6. PHP & AJAX PHP and AJAX AJAX INTRODUCTION AJAX= Asynchronous JavaScript And XML AJAX က web browser န ႔web server ၾက ထ က နdata တ က ပ ႔ဖ ႔န ႔လက ခ ဖ ႔အတ က JavaScript က အသ ပ ပ တ ယ AJAX နည ပည ၾက င user က အ ပ င အလ တ စ ခ လ ပ လ က တ ႔အခ မ web page တ စ ခ လ က relode လ ပ လ က တ မ မဟ တ ပ န ႔ န က က ယ မ web server န ႔data exchange လ ပ တ ႔အတ က web page တ က ပ ပ တ ႔ responsive ဖစ ပ တယ AJAX က အ က ပ standards တ ပၚမ အ ခခ ထ ပ တ ယ -JavaScript -XML -HTML -CSS PHP က လ႔လ တ ႔အခ မ AJAX က မသ လ ႔မ ဖစ ပ ဘ JavaScript, XML, HTML,CSS ဒ တ မသ ရင PHP လ ႔လ လ ည သ ပ တ ႔မထ ပ ဘ.. အ ဒ အက န သ ရမ ဖစ ပ တယ.. အ လ ဆ က စပ ပ အသ ခ ရမ ဖစ လ ႔ပ AJAX အ နန ႔major browser တ အ လ က support လ ပ ၾကပ တယ ဒ ၾက င AJAX application တ က browser န ႔ platform ပၚမ မ ခ မ မရ ဘ Cross Platform, Cross Browser Technology လ ႔ဆ င ပ တယ AJAX Uses XML And HTTP Requests ရ ရ သ မန နည န ႔ ရ ထ တ ႔web application တစ ခ မ html form တ စ ခ က သ ပ input တစ ခ က web server ဆ က submit လ ပ ပ မယ web server က data က process လ ပ ပ တ ႔အခ မ user ဆ က web page အသ စ တ စ ခ က return ပန လ ပ မယ user က input ပ တ ႔အခ တ င မ web page အသစ တ စ ခ က server က ပန ပ ရတ ဖစ တ ႔အတ က ဒ ရ ရ နည န ႔ ရ တ က ပ တယ ပ တ ႔user friendly မ ဖစ ပ ဘ AJAX နည ပည က သ ရင web application တ က web page တ စ ခ က relode လ ပ စရ မလ ပ န ႔data တ က ပ ႔ င ထ တ င တ ဖစ ပ တယ ဒ က စၥက န က က ယ မ server ဆ က HTTP request တ ပ ပ ႔ ခင န ႔အလ ပ လ ပ တ ဖစ ပ တယ server က data ပန လ တ ႔အခ JavaScript က သ ပ web page ရ ႕အစ တ အပ င လ က ပ modify လ ပ တ ဖစ ပ တယ ရ ႕လ မယ ႔ဥပမ တ က ၾက ည ရင န လ ည မ ပ PHP and AJAX AJAX မ တ ႔ server ရယ လ ႔မရ ပ ဘ.. AJAX ဆ တ က န တ ႔ရ ႕ browser ပၚမ ပ run တ ႔ နည ပည တ စ ခ ဖစ ပ တ ယ browser န ႔web server ရ ႕ၾက မ HTTP requests (asynchronous data transfer) က သ ပ တယ ဆ လ တ က web page တစ ခ လ က server ဆ က ပ ႔တ မဟ တ ပ အ ဒ web page ထ က အခ က အလက အနည ငယ အစ တ အပ င လ က ပ ပ ႔တ ဖစ ပ တ ယ ပ ရရင တ ႔AJAX က web server software တ ပၚမ မမ ခ တ ႔ web browser technology တ စ ခ ဖစ ပ တယ ဒ tutorial ထ မ တ ႔ PHP server ပၚမ run တ ႔ဥပမ တ က အသ ပ ဖ ပ ပ ပ မယ 54 Youth Dreams 54

55 AJAX XMLHttpReuest XMLHttpRequest object က တ ႔AJAX ရ ႕အဓ က သ ႔ခ က ဖစ ပ တယ July 2000 Internet Explorer ထ က ကတည က သ လ ႔ရတ ဖစ ပ တယ ဒ ပမယ ႔2005 မ AJAX န ႔Web 2.0 အ ၾက င ပ ဖစ ၾက တ ႔အခ မ အ ပည အ၀အသ ခ ၾက တ ဖစ ပ တ ယ မတ ည တ ႔browser တ အ နန ႔XMLHttpRequest object က ဖန တ ဖ ႔အတ က က ပ တ ႔နည လမ တ က သ ၾက ပ တယ Internet Explorer က ActiveXObject က အသ ပ ပ တ ယ တ ခ browser တ က တ ႔build in JavaScript object တစ ခ ဖစ တ ႔XMLHttpRequest က အသ ပ ပ တ ယ အ က က code လ က ဒ ပသန က ပလည စတ ႔အရ ရ င ဆ နည လ မ ပ var XMLHttp=null if (window.xmlhttprequest) XMLHttp=new XMLHttpRequest() else if (window.activexobject) XMLHttp=new ActiveXObject("Microsoft.XMLHTTP") အရင ဆ XMLHttpRequest object က အသ ပ ဖ ႔အတ က XMLHttp variable တ စ ခ က ဖန တ ပ တယ တ န ဖ က တ ႔null လ ႔သ တ မ တ ပ ခ ႔ပ တ ယ ပ တ ႔ န က မ window.xmlhttprequest ဆ တ ႔object လ available ဖစ မ ဖစ စစ ပ တယ Firefox, Opera, Safari န က ပ င version တ မ ဆ ရင available ဖစ မ ဖစ ပ တ ယ တ ကယ လ ႔available ဖစ တယ ဆ ရင XMLHttp=new XMLHttpRequest() ဆ ပ တ ႔ object အသစ တ စ ခ ဖန တ ပ တ ယ available မ ဖစ ရင တ ႔window.ActiveXObject က available ဖစ မ ဖစ စစ ပ တ ယ Internet Explorer 5.5 န ႔ န က ပ င တ အ လ မ available ဖစ ပ တ ယ available ဖစ တ ယ ဆ ရင XMLHttp=new ActiveXObject() ဆ ပ တ ႔object အသစ တ စ ခ က ဖန တ ပ တ ယ ပရ ဂရမ မ တ အ နန ႔ဒ ထ က ပ က င တ ႔ပ မန တ ႔XMLHttpRequest object က ပ စ သ က င ပ တယ အ က က ဥပမ လ က တ ႔Microsoft.XMLHTTP အစ Xsxml2.XMLHTTP ဆ တ ႔Microsoft ရ ႕latest version က load လ ပ တ ဖစ ပ တ ယ အ ဒ က တ ႔IE 6 န ႔ န က ပ င မ မ available ဖစ တ ဖစ ပ တ ယ function GetXmlHttpObject() var xmlhttp=null; try // Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest(); catch (e) // Internet Explorer try 55 Youth Dreams 55

56 xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); catch (e) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlhttp; ဒ ဥပမ က ဘ က ပ တ လ ဆ ရင အရင ဆ XMLHttpRequest object က သ ဖ ႔အတ က XMLHttp ဆ တ ႔variable လ က ဖန တ ပ တယ အ ဒ န က web standarads (Mozila, Opera န ႔Safari)အရXMLHttp= new XMLHttpRequest() object က ဖန တ ဖ ႔ၾက စ ပ တ ယ န က တခ Microsoft နည လ မ န ႔IE 6 န ႔ န က ပ င အတ က XMLHttp=new ActiveXObject( Msxml2.XMLHTTP object က ဖန တ ဖ ႔ၾက စ ပ တယ အ ဒ မ error ဖစ တ ယ ဆ မ အ ဟ င နည လ မ (IE 5.5) XMLHttp=new ActiveXObject( Microsoft.XMLHTTP ) က ၾက စ ပ တယ AJAX Suggest အ က က AJAX ဥပမ မ user က web form တစ ခ ထ က data ရ က ထည ပ တ ႔web page တစ ခ က web server န ႔ ဘယ လ communticate လ ပ တယ ဆ တ က သရ ပ ပသ မ ဖစ ပ တ ယ အ က ကလ ပ စ မ လ ရ မ ပ box လ ထ မ character လ တ စ ခ ခ က ရ က ထ ည တ န ႔suggestion မ ပၚလ မယ ဒ ဥပမ မ page သ ခ ပ ၀င ပ မယ - ရ ရ HTML page - JavaScript page - PHP page The HTML Form အခ က တ ႔HTML page ဖစ ပ တ ယ သ ႔မ form အတ က HTML code ရယ JavaScript က ခၚတ ႔link ရယ ပ ၀င ပ တ ယ ဒ html file က ajaxtesting.html လ ႔ ပ ပ မယ <html> <head> <script src="clienthint.js"></script> </head> <body> 56 Youth Dreams 56

57 <form> First Name: <input type="text" id="txt1" onkeyup="showhint(this.value)"> </form> <p>suggestions: <span id="txthint"></span></p> </body> </html> ဒ ဥပမ မ ဆ ရင txt1 ဆ တ ႔Input filed လ ပ တ ႔ရ ရ HTML form လ ပ ပ တယ အလ ပ လ ပ ပ က တ ႔ 1. user က input field လ ထ မ keyboard ပၚက key တ စ ခ က ပ ပ တ ႔release လ ပ လ က တ ႔အ ခ event တစ ခ က အစပ ပ ပ တ ယ 2. evernt က အစပ ပ တ ႔အခ န မ showhint() ဆ တ ႔function လ က ခၚ ပ တ ႔execute လ ပ ပ တ ယ 3. form ရ ႕ အ က မ txthint ဆ တ ႔<span> လ ရ ပ တယ အ ဒ က တ ႔showHint() က ပန လ တ ႔return data လ ပၚမ ႔ နရ လ ပ ဖစ ပ တ ယ အ က က JavaScript code က တ ႔clienthint.js လ ႔သ မ မ ဖစ ပ HTML document န ႔လ င လ ပ ထ တ ဖစ ပ တယ var xmlhttp; function showhint(str) if (str.length==0) document.getelementbyid("txthint").innerhtml=""; return; xmlhttp=getxmlhttpobject(); if (xmlhttp==null) alert ("Browser does not support HTTP Request"); return; var url="gethint.php"; url=url+"?q="+str; url=url+"&sid="+math.random(); xmlhttp.onreadystatechange=statechanged; xmlhttp.open("get",url,true); xmlhttp.send(null); 57 Youth Dreams 57

58 function statechanged() if (xmlhttp.readystate==4 xmlhttp.readystate=="complete") document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext; function GetXmlHttpObject() var xmlhttp=null; try // Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest(); catch (e) // Internet Explorer try xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); catch (e) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlhttp; // JavaScript Document ဒ ဥပမ လ က ရ င ရရင တ ႔showHint()function က inpurt field ထ မ က န တ ႔character တစ လ ရ က လ က တ ႔ အခ တ င အလ ပ လ ပ ပ တယ အကယ input filed ထ မ input ရ ပ သ ဆ လ တ က str.length>0 ဖစ သ တ ယ ဆ ရင အ က ပ အတ င execute လ ပ ပ တ ယ 1. server က ပ ပ ႔မယ url filename က သတ မ တ ပ တယ ဒ မ တ ႔gethint.php ပ 2. input filed ထ မ ရ က နမယ ႔ content (character) န ႔ ယ ဥ တ ပ တ ႔ parameter (q) လ က ပ င ထ ည ပ တ ယ 3. server က cached file က သ မ တ က နက က ယ ဖ ႔random number တ စ ခ က ထ ပ ပ င ထ ည ပ တ ယ 58 Youth Dreams 58

59 4. GetXmlHttpObject function က ခၚ ပ တ ႔XMLHTTP object က ဖန တ ယ ပ တယ ပ တ ႔ ပ င လ မ တ စ ခ ဖစ တ ႔အခ အ ဒ object အ နန ႔StateChanged ဆ တ ႔function လ က execute လ ပ စပ တယ 5. ပ လ က တ ႔url အတ င XMLHTTP object က ဖ င လ က ပ တ ယ 6. server ဆ က HTTP request က လ မ ပ ႔လ က ပ တယ input filed က ဗလ ဖစ နတယ ဆ ရင function က txthint ရ ႕placeholder (suggestion ပၚတ ႔ နရ ) မ ရ နတ ႔ content (စ တ ) အ လ က ရ င လင ပစ လ က ပ တ ယ The statechanged() Function XMLHTTP object ရ ႕state ပ င လ တ ႔အခ တ င မ ဒ function က execute(တ က ခ က ) လ ပ ပ တ ယ state က 4 ဒ မ မဟ တ complete အ ဖစ ပ င တ ႔အခ txthint ရ ႕content က သ response လ ပ တ ႔text န ႔ ဖည ပ တ ယ The GetXmlHttpObject() Function AJAX applications အ နန ႔XML support လ ပ တ ႔browser န ႔ပ run မ ဖစ တ ပအတ က GetXMLHttpObjet() က ခၚ ပ တ ဒ ပသက နည လမ တစ ခ မဟ တ တ စ ခ န ႔ ဖရ င င စဖ ႔XMLHTTP object အမ မ က ဖန တ ပ တယ အခ က န တ ႔PHP page အတ က ဖစ ပ တယ JavaScript code က ခၚတ ႔လ အပ တ ႔server page က တ ႔gethint.php လ ႔ ခၚတ ႔Php file လ ပ ဒ gethint.php ဖ င လ ထ က code မ တ ႔န မည တ ရ ႕array တစ ခ က စစ ပ တ ႔client ဆ က သက ဆ င ရ အမည က return ပန ပ ပ မယ // Fill up array with names $a[]="anna"; $a[]="brittany"; $a[]="cinderella"; $a[]="diana"; $a[]="eva"; $a[]="fiona"; $a[]="gunda"; $a[]="hege"; $a[]="inga"; $a[]="johanna"; $a[]="kitty"; $a[]="linda"; $a[]="nina"; $a[]="ophelia"; $a[]="petunia"; $a[]="amanda"; $a[]="raquel"; $a[]="cindy"; $a[]="doris"; $a[]="eve"; 59 Youth Dreams 59

60 $a[]="evita"; $a[]="sunniva"; $a[]="tove"; $a[]="unni"; $a[]="violet"; $a[]="liza"; $a[]="elizabeth"; $a[]="ellen"; $a[]="wenche"; $a[]="vicky"; //get the q parameter from URL $q=$_get["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0) $hint=""; for($i=0; $i<count($a); $i++) if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) if ($hint=="") $hint=$a[$i]; else $hint=$hint.", ".$a[$i]; //Set output to "no suggestion" if no hint were found //or to the correct values if ($hint == "") $response="no suggestion"; else $response=$hint; 60 Youth Dreams 60

61 //output the response echo $response; JavaScript ဖ င က န(strlen($q)>0) ဖစ တ ႔အခ တ င text တစ ခ ခ က လ မ ပ ႔တ ႔အခ အ က ပ အတ င ဖစ ပၚပ တယ 1. JavaScript က နလ မ ပ ႔တ ႔character န ႔match ဖစ တ ႔အမည က ရ တယ 2. န မည တစ ခ ထက ပ ပ အတ မ တ ယ ဆ ရင response string မ အမည တ အ လ ပ လ မယ 3. ဘ မ match ဖစ တ မ တ ႔ရင တ ႔no suggestion ဆ ပ response ဖစ မယ 4. တစ ခ ထ က ပ ပ တ ႔ရင ဒ န မည တ က response ပ မယ 5. ဒ response တ အ လ က txthint placeholder က ပ ႔ ပ မယ အခ အခ န မ clienthint.js, gethint.php ajaxtesting.html ဖ င သ ခ က တ ည တ ႔folder directory အ က မ save ခ ႔တ ဖစ ရပ မယ.. အ ဒ ဆ ရင တ ႔ajaxtesting.html က browser မ run တ ႔အခ PHP န ႔AJAX န ႔တ သ ထ တ ႔ ပ စရ web application ပ စ လ တစ ခ က ရပ ပ ခင ဗ :D PHP AND AJAX XML EXAMPLE အခ တ ခ က တ ႔AJAX က XML file န ႔ယ ဥ တ သ င ပ တ ယ အ က က ဥပမ မ web page တစ ခ က န AJAX နည ပည က သ ပ တ ႔XML file တ စ ခ စ က အခ က အလက တ က ဘယ လ ခၚယ သ င (fetch) လ ပ င တ ယ ဆ တ က လ ႔လ မ ဖစ ပ တ ယ Select a CD: ဆ ပ တ ႔စ သ လ ရ မယ ဘ မ drop down box လ ရ မယ အ ဒ ထ မ ရ ခ ယ စရ သ ခ ရ မယ.. တစ ခ က ရ လ က ရင အ က မ အ ဒ န ႔ပတ သ က တ ႔CD info က ပ ပ မယ ဒ မ လ ပ ဒ ဥပမ လ မ လည HTML form တစ ခ XML file တစ ခ JavaScript တ စ ခ PHP page တ စ ခ စ စ ပ င လ ခ ပ ၀င ပ မယ THE HTML FORM ဒ အ က က ဥပမ လ မ တ ႔HTML form လ ပ မယ JavaScript ဖ င ဆ က လ ည လ င ခ တ ထ တ ဖစ ပ တ ယ ဒ HTML code တ က တ ႔ajaxxml.html လ ႔save လ က ပ တယ <html> <head> <script src="selectcd.js"></script> </head> <body> <form> Select a CD: <select name="cds" onchange="showcd(this.value)"> <option value="bob Dylan">Bob Dylan</option> <option value="bee Gees">Bee Gees</option> <option value="cat Stevens">Cat Stevens</option> </select> </form> 61 Youth Dreams 61

62 <p> <div id="txthint"><b>cd info will be listed here.</b></div> </p> </body> </html> ဒ က ရ ရ င တ ႔HTML form လ ပ ဖစ ပ တယ cds ဆ တ ႔drop down box လ ပ မယ အ ဒ ရ ႕ အ က မ တ ႔txtHint လ ႔ ခၚတ ႔div တစ ခ ပ ပ မယ အ ဒ div က web server က န ပန လ မယ ႔အခ က အလက တ က ပ ပ မယ ႔ နရ placeholder အ နန ႔အသ ပ တ ဖစ ပ တယ user က data တစ ခ က ရ လ က တ ႔အခ showcd ဆ တ ႔function က execute(run) လ ပ မ ဖစ ပ တယ onchange event ပၚမ မ တည ပ တ ႔function က စrun မ ဖစ ပ တယ ဆ လ တ က user က drop down box ထ က တ န ဖ က ပ င လ က တ ႔အခ တ င ရ ခ ယ မ ပ င လ က တ ႔အခ တ င မ ပ ႔showCD ဆ တ ႔function က သ ခၚမ ဖစ ပ တ ယ XML file အ နန ႔က တ ႔ အ က က code လ က cd_catalog.xml လ ႔save ပ ခ နက ajaxxml.html ဆ တ ႔file န ႔တ ည တ ႔folder အ က မ ထ လ က ပ တယ <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</title> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1982</YEAR> </CD> <CD> <TITLE>Still got the blues</title> <ARTIST>Gary Moore</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin records</company> <PRICE>10.20</PRICE> 62 Youth Dreams 62

63 <YEAR>1990</YEAR> </CD> <CD> <TITLE>Eros</TITLE> <ARTIST>Eros Ramazzotti</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>BMG</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR> </CD> <CD> <TITLE>One night only</title> <ARTIST>Bee Gees</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.90</PRICE> <YEAR>1998</YEAR> </CD> <CD> <TITLE>Sylvias Mother</TITLE> <ARTIST>Dr.Hook</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS</COMPANY> <PRICE>8.10</PRICE> <YEAR>1973</YEAR> </CD> <CD> <TITLE>Maggie May</TITLE> <ARTIST>Rod Stewart</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Pickwick</COMPANY> <PRICE>8.50</PRICE> <YEAR>1990</YEAR> </CD> <CD> <TITLE>Romanza</TITLE> <ARTIST>Andrea Bocelli</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.80</PRICE> <YEAR>1996</YEAR> </CD> <CD> <TITLE>When a man loves a woman</title> <ARTIST>Percy Sledge</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>8.70</PRICE> <YEAR>1987</YEAR> </CD> <CD> <TITLE>Black angel</title> <ARTIST>Savage Rose</ARTIST> 63 Youth Dreams 63

64 <COUNTRY>EU</COUNTRY> <COMPANY>Mega</COMPANY> <PRICE>10.90</PRICE> <YEAR>1995</YEAR> </CD> <CD> <TITLE>1999 Grammy Nominees</TITLE> <ARTIST>Many</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Grammy</COMPANY> <PRICE>10.20</PRICE> <YEAR>1999</YEAR> </CD> <CD> <TITLE>For the good times</title> <ARTIST>Kenny Rogers</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Mucik Master</COMPANY> <PRICE>8.70</PRICE> <YEAR>1995</YEAR> </CD> <CD> <TITLE>Big Willie style</title> <ARTIST>Will Smith</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR> </CD> <CD> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>8.20</PRICE> <YEAR>1971</YEAR> </CD> <CD> <TITLE>Soulsville</TITLE> <ARTIST>Jorn Hoel</ARTIST> <COUNTRY>Norway</COUNTRY> <COMPANY>WEA</COMPANY> <PRICE>7.90</PRICE> <YEAR>1996</YEAR> </CD> <CD> <TITLE>The very best of</title> <ARTIST>Cat Stevens</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Island</COMPANY> <PRICE>8.90</PRICE> <YEAR>1990</YEAR> </CD> 64 Youth Dreams 64

65 <CD> <TITLE>Stop</TITLE> <ARTIST>Sam Brown</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>A and M</COMPANY> <PRICE>8.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Bridge of Spies</TITLE> <ARTIST>T'Pau</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Siren</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR> </CD> <CD> <TITLE>Private Dancer</TITLE> <ARTIST>Tina Turner</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Capitol</COMPANY> <PRICE>8.90</PRICE> <YEAR>1983</YEAR> </CD> <CD> <TITLE>Midt om natten</title> <ARTIST>Kim Larsen</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Medley</COMPANY> <PRICE>7.80</PRICE> <YEAR>1983</YEAR> </CD> <CD> <TITLE>Pavarotti Gala Concert</TITLE> <ARTIST>Luciano Pavarotti</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>DECCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1991</YEAR> </CD> <CD> <TITLE>The dock of the bay</title> <ARTIST>Otis Redding</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>7.90</PRICE> <YEAR>1987</YEAR> </CD> <CD> <TITLE>Picture book</title> <ARTIST>Simply Red</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Elektra</COMPANY> <PRICE>7.20</PRICE> 65 Youth Dreams 65

66 <YEAR>1985</YEAR> </CD> <CD> <TITLE>Red</TITLE> <ARTIST>The Communards</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>London</COMPANY> <PRICE>7.80</PRICE> <YEAR>1987</YEAR> </CD> <CD> <TITLE>Unchain my heart</title> <ARTIST>Joe Cocker</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> <PRICE>8.20</PRICE> <YEAR>1987</YEAR> </CD> </CATALOG> အ က က code က တ ႔selectcd.js ဆ ပ တ ႔သ မ မယ ႔JavaScript code ပ ဖစ ပ တ ယ var xmlhttp function showcd(str) xmlhttp=getxmlhttpobject() if (xmlhttp==null) alert ("Browser does not support HTTP Request") return var url="getcd.php" url=url+"?q="+str url=url+"&sid="+math.random() xmlhttp.onreadystatechange=statechanged xmlhttp.open("get",url,true) xmlhttp.send(null) function statechanged() if (xmlhttp.readystate==4 xmlhttp.readystate=="complete") document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext function GetXmlHttpObject() var xmlhttp=null; try // Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest(); catch (e) 66 Youth Dreams 66

67 // Internet Explorer try xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); catch (e) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlhttp; statechanged() န ႔GetXmlHttpObject တ က တ ႔ ရ ႕ဥပမ တ စ ခ ကအတ င ပ ပ showcd() function ရ ႕အလ ပ လ ပ ပ က တ ႔ drop down box ထ က item တ စ ခ က ရ လ က ပ ဆ တ န ႔ အလ ပ လ ပ တ ဖစ ပ တ ယ သ လ ည ပ အ ရ ႕မ လ႔လ ခ ႔တ ႔showHint() လ မ ပ အလ ပ လ ပ တ ဖစ ပ တယ JavaScript က နလ မ ခၚမယ ႔server page က တ ႔getcd.php ဆ တ ႔ဖ င လ ဖစ ပ တယ အ က ပ အတ င ရ ပ သ မ ပ မယ XML document cd_catalog.xml က load လ ပ ဖ ႔အတ က XML DOM က သ ပ PHP န ႔ ရ ထ တ ဖစ ပ တ ယ XML file ထ က နquery run ပ တ ႔HTML အ နန ႔result က return ပန လ တ ဖစ ပ တယ $q=$_get["q"]; $xmldoc = new DOMDocument(); $xmldoc->load("cd_catalog.xml"); $x=$xmldoc->getelementsbytagname('artist'); for ($i=0; $i<=$x->length-1; $i++) //Process only element nodes if ($x->item($i)->nodetype==1) if ($x->item($i)->childnodes->item(0)->nodevalue == $q) $y=($x->item($i)->parentnode); $cd=($y->childnodes); for ($i=0;$i<$cd->length;$i++) //Process only element nodes if ($cd->item($i)->nodetype==1) echo($cd->item($i)->nodename); echo(": "); echo($cd->item($i)->childnodes->item(0)->nodevalue); echo("<br />"); 67 Youth Dreams 67

68 JavaScript က နPHP page က query လ မ ပ ႔ ပ ခၚလ က တ ႔အခ အ က ပ အတ င ဖစ ပ ပ တ ယ 1. PHP က cd_catalog.xml file ရ ႕XML DOM object က ဖန တ လ က ပ တယ 2. artist elements (nodetypes=1) တ အက န လ က JavaScript က နပ ႔လ က တ န ႔match ဖစ တ ႔အမည က loop ပတ ပ ရ ပ တယ 3. မ န က န တ ႔artist ပ တ ႔CD က တ ႔သ ပ တယ 4. album အခ က အလက တ က Output အ နန ႔ရ ပ တ ႔txtHint placeholder ဆ က လ မ ပ ႔လ က ပ တယ န က ထပ ဥပမ တ စ ခ ပ သ ပ ပ ဒ ဟ လ ည ပ စရ က င မယ လ ႔ထ င ပ တယ PHP and AJAX RSS Reader RSS Reader က သ ပ တ ႔RSS Feeds တ က ဖတ လ ႔ရပ တ ယ RSS ဆ တ က တ ႔သတ င တ up to date အခ က အလက တ က မန မန ဆ န ဆ န သ ရ စတ ႔ဟ ဖစ ပ တယ AJAX RSS Reader အခ အ က က ဥပမ မ တ ႔webpage က refresh လ ပ စရ မလ ဘ န ႔RSS ရ ႕content တ က load လ ပ ပ တ ႔RSS reader တ စ ခ က ရ မ ဖစ ပ တယ ဒ ဥပမ မ တ ႔HTML page တ စ ခ JavaScript တ စ ခ န ႔PHP တစ ခ ပ ၀င မ ဖစ ပ တ ယ The HTML Form ဒ ဖ င လ မ getrss.js ဆ တ ႔JavaScript က လ မ ခ တ ထ ပ တယ <html> <head> <script type="text/javascript" src="getrss.js"></script> </head> <body> <form> Select an RSS-Feed: <select onchange="showrss(this.value)"> <option value="google">google News</option> <option value="msnbc">msnbc News</option> </select> </form> <p><div id="rssoutput"> <b>rss Feed will be listed here.</b></div></p> </body> </html> က န တ ႔ တ ႔တ ႔အတ င ပ ဒ HTML page မ drop-down box တစ ခ န ႔HTML form တစ ခ ပ ၀င ပ တယ 68 Youth Dreams 68

69 user က drop down box ထ က န option တစ ခ က ရ လ က တ ႔အခ event တ စ ခ စတ င ဖစ ပ တ ယ အ ဒ အခ မ showrss() ဆ တ ႔function က လ မ ခၚပ တယ အ က မ ပ တ ႔rssOutput ဆ တ ႔<div> က တ ႔showRSS() function က န return ပန လ တ ႔data တ က ပၚ ပ မယ ႔placeholder အ နန ႔သ တ ဖစ ပ တ ယ The JavaScript အ က က code က တ ႔getrss.js ဆ တ ႔JavaScript code ပ ဖစ ပ တယ var xmlhttp function showrss(str) xmlhttp=getxmlhttp Object() if (xmlhttp==null) alert ("Browser does not support HTTP Request") return var url="getrss.php" url=url+"?q="+str url=url+"&sid="+math.random() xmlhttp.onreadystatechange=statechanged xmlhttp.open("get",url,true) xmlhttp.send(null) function statechanged() if (xmlhttp.readystate==4 xmlhttp.readystate=="complete") document.getelementbyid("rssoutput").innerhtml=xmlhttp.responsetext function GetXmlHttpObject() var xmlhttp=null; try // Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest(); catch (e) // Internet Explorer try xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); catch (e) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlhttp; JavaScript code က နလ မ ခၚလ က တ ႔getrss.php ဆ တ ႔PHP file လ က တ ႔ အ က ပ အတ င ပ.. သ က တ ႔ server page ပ ႔ 69 Youth Dreams 69

70 //get the q parameter from URL $q=$_get["q"]; //find out which feed was selected if($q=="google") $xml=(" elseif($q=="msnbc") $xml=(" $xmldoc = new DOMDocument(); $xmldoc->load($xml); //get elements from "<channel>" $channel=$xmldoc->getelementsbytagname('channel')->item(0); $channel_title = $channel->getelementsbytagname('title') ->item(0)->childnodes->item(0)->nodevalue; $channel_link = $channel->getelementsbytagname('link') ->item(0)->childnodes->item(0)->nodevalue; $channel_desc = $channel->getelementsbytagname('description') ->item(0)->childnodes->item(0)->nodevalue; //output elements from "<channel>" echo("<p><a href='". $channel_link. "'>". $channel_title. "</a>"); echo("<br />"); echo($channel_desc. "</p>"); //get and output "<item>" elements $x=$xmldoc->getelementsbytagname('item'); for ($i=0; $i<=2; $i++) $item_title=$x->item($i)->getelementsbytagname('title') ->item(0)->childnodes->item(0)->nodevalue; $item_link=$x->item($i)->getelementsbytagname('link') ->item(0)->childnodes->item(0)->nodevalue; $item_desc=$x->item($i)->getelementsbytagname('description') ->item(0)->childnodes->item(0)->nodevalue; echo ("<p><a href='". $item_link. "'>". $item_title. "</a>"); echo ("<br />"); echo ($item_desc. "</p>"); JavaScript က နoption တ စ ခ လ မ ပ ႔လ က တ ႔အခ အ က ပ အတ င အလ ပ လ ပ ပ တ ယ - ဘယ RSS feed က ရ ထ တ ယ ဆ တ PHP ကစစ ပ တ ယ - XML DOM object တ စ ခ က ရ ခ ယ ထ တ ႔RSS feed အတ က ဖန တ လ က ပ တယ - RSS channel ထ က တ ႔ရ လ တ ႔element တ က output ပ ပ ပ တယ - RSS items တ ထ က ပထ မဆ သ ခ က loop ပတ န ပ တ ႔output ပ ပ ပ တ ယ အခ အခ န မ rssreader.html က run မယ ဆ ရင ရပ ပ ခင ဗ 70 Youth Dreams 70

71 PHP AND AJAX POLL အ က က Ajax example မ web page က relode လ ပ စရ မလ ဘ န ႔result က ပန ပ ပ င တ ႔Poll တစ ခ က ပသသ မ ဖစ ပ တ ယ ဒ ဥပမ မ လ ည စ မ က လ ခ ပ ၀င ပ မယ - HTML form တ စ ခ - JavaScript တ စ ခ - PHP page တ စ ခ န ႔ - Yes, No result တ က သ မ ဖ ႔text file တစ ခ တ ႔ပ ၀င ပ တ ယ The HTML Form အခ အရင ဆ က တ ႔HTML စ မ က ဖစ ပ တယ ရ ရ HTML form တ စ ခ ပ ဖစ ပ တ ႔JavaScript ဖ င က လ မ ပ link ခ တ ထ ပ တ ယ <html> <head> <script src="poll.js"></script> </head> <body> <div id="poll"> <h2>do you like PHP and AJAX so far?</h2> <form> Yes: <input type="radio" name="vote" value="0" onclick="getvote(this.value)"> <br />No: <input type="radio" name="vote" value="1" onclick="getvote(this.value)"> </form> </div> </body> </html> ဒ လ က ajaxpoll.html ဆ ပ save ထ လ က ပ တ ယ သ ႔ရ ႕အလ ပ လ ပ ပ လ က တ ႔<div> tag ထ မ Yes န ႔No ဆ တ ႔radio button လ စ ခ ပ ၀င တ ႔form လ ရ ပ တယ user က yes ဒ မ မဟ တ no က ရ လ က တ ႔အခ မ event တ စ ခ အလ ပ လ ပ ပ တယ အ ဒ event ဖစ တ ႔အခ မ getvote() ဆ တ ႔function က ခၚ ပ execute လ ပ ပ တ ယ getvote() function က န ပန လ တ ႔data တ က form မ replace ပန လ ပ ပ တယ The Text File text file က တ ႔poll_result.txt ဆ ပ တ ႔save ပ မယ poll က ရတယ.. data တ က သ မ ဖ ႔ပ ဖစ ပ တ ယ အ က ကပ စ အတ င သ မ မ ပ 0 0 ပထ မလ တ ႔န ပ တ က Yes votes တ က က ယ စ ပ ပ တ ႔ ရ ႕ န က က န ပ တ က တ ႔No votes တ က က ယ စ ပ ပ တ ယ ဥပမ.. က န တ ႔Yes က တခ vote လ က ရင အ ရ ႕က 0 က 1 ဖစ သ ပ မယ The JavaScript JavaScript code တ က တ ႔poll.js န ႔သ မ ပ မယ 71 Youth Dreams 71

72 var xmlhttp function getvote(int) xmlhttp=getxmlhttpobject() if (xmlhttp==null) alert ("Browser does not support HTTP Request") return var url="poll_vote.php" url=url+"?vote="+int url=url+"&sid="+math.random() xmlhttp.onreadystatechange=statechanged xmlhttp.open("get",url,true) xmlhttp.send(null) function statechanged() if (xmlhttp.readystate==4 xmlhttp.readystate=="complete") document.getelementbyid("poll"). innerhtml=xmlhttp.responsetext; function GetXmlHttpObject() var objxmlhttp=null if (window.xmlhttprequest) objxmlhttp=new XMLHttpRequest() else if (window.activexobject) objxmlhttp=new ActiveXObject("Microsoft.XMLHTTP") return objxmlhttp Yes ဒ မ မဟ တ No က HTML form ထ မ select လ ပ လ က တ ႔အခ getvote() function က လ အလ ပ လ ပ ပ တ ယ အခ န က ဆ က တ ႔JavaScript ထ က နလ မ ခၚထ တ ႔poll_vote.php ပ ဖစ ပ တ ယ $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll_result.txt"; $content = file($filename); //put content in array $array = explode(" ", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) 72 Youth Dreams 72

73 $yes = $yes + 1; if ($vote == 1) $no = $no + 1; //insert votes to txt file $insertvote = $yes." ".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); <h2>result:</h2> <table> <tr> <td>yes:</td> <td> <img src="poll.gif" width=' echo(100*round($yes/($no+$yes),2)); ' height='20'> echo(100*round($yes/($no+$yes),2)); % </td> </tr> <tr> <td>no:</td> <td> <img src="poll.gif" width=' echo(100*round($no/($no+$yes),2)); ' height='20'> echo(100*round($no/($no+$yes),2)); % </td> </tr> </table> Yes (0), No (1) စတ ႔တ န ဖ တ က JavaScript က နလ မ ပ ႔ ပ ပ တ ယ အ ဒ န က မ တ ႔ - poll_result.txt file ရ ႕content က ယ ပ တ ယ - အ ဒ contact တ က variable ပ င ပ တ ႔variable တ စ ခ က JavaScript ကပ ႔လ တ ႔အတ င တ စ တ ပ တယ - အ ဒ တ စ တ ပ တ ႔result က poll_result.txt ဖ င မ ရ လ က ပ update လ ပ ပ တ ယ - poll result ရ ႕graphical representation က ထ တ ပလ က ပ တယ အခ အခ န မ ajaxpoll.html က run လ က မယ ဆ ရင မ လ င ထ သလ ပ Do you like PHP & AJAX so far? ဆ တ ႔poll လ က Yes, No button စ ခ န ႔ တ ႔ရမ ဖစ ပ တ ယ ajaxpoll.html ဖ င က လ သ လ ပင ပ တ ႔ဥပမ Do you like PHP & AJAX so far ဆ တ ႔ နရ မ နင င ႔က ခ စ လ Yes နရ မ ခ စ တ ယ လ ႔ ထ လ က No နရ မ Yes လ ႔ ပ င ပ ရ လ က ပ ႔. ပ ရင run ၾကည လ က ပ ႔ :P 73 Youth Dreams 73

74 Chapter 7. PHP MyAdmin Basic က န တ ႔အ နန ႔PHP, MySQL န ႔Apache အ လ ပ ၀င ပ သ Package ဖစ တ ႔XAMPP က အသ ပ နတ ဖစ ပ တ ယ. အလ အ လ က အ နန ႔root ဆ တ ႔username န ႔password မပ ဘ ဖန တ ထ ပ မ ဖစ ပ တယ.. အခ Database တ န ႔ က န တ ႔စတ င အလ ပ လ ပ တ ႔မ ဖစ လ ႔အမ န တ ကယ username န ႔password တစ ခ က ဖန တ သင ပ တ ယ.. MySQL ရ ႕User အခ င အ ရ တ က အနည ငယ လ က ဖစ ဖစ န လည ဖ ႔လ အပ ပ တ ယ.. Creating a New User Database တ န ႔အလ ပ လ ပ တ ႔မယ ဆ ရင ဆ ပ ၀င လ က ပ. PHP My Admin ဆ တ ႔ tool က အသ ပ ပ Database တ န ႔အလ ပ လ ပ ရမ ဖစ ပ တ ယ.. User အသစ တ စ ယ က က SQL Statement က သ ပ ဖန တ င သ လ ဒ မ မဟ တ PHP Admin ထ မ အသင ပ တ ႔ Create New User က ပ ပ တ ႔လ လ ယ က စ ဖန တ င ပ တယ.. လ ႔Web Browser မ ရ က တ ႔အခ အ က က နရ က ရ က လ မ ဖစ ပ တယ အ ဒ မ Privileges ဆ တ ႔ နရ က ၀င လ က ပ.. 74 Youth Dreams 74

75 Privileges ဆ တ ႔ နရ က ၀င လ က တ ႔အခ အ က ပ တ င Create a new User ဆ တ က တ ႔ပ မယ.. အ ဒ လင လ က ပ ပ user အသစ က ဖန တ င ပ တယ 75 Youth Dreams 75

76 က န ႔အ နန ႔Username နရ မ moemyintshein host က localhost န ႔password က moemyintshein လ ႔ပ ပ လ က ပ တ ႔Global privileges မ Check All လ ပ ပ ပ တ ယ.. ပ တ ႔အခ Go က ပ ပ တ ႔user အသစ က ဖန တ လ က ပ တယ ခင ဗ.. အ ဒ အခ မ အ က ပ အတ င SQL Statement တ က အလ အ လ က ဖန တ ပ ပ တ ႔execute လ ပ ထ က.. you have added a new user ဆ တ ႔Message ပမ ဖစ ပ တယ.. ဒ ဆ ရင တ ႔user အသ စ က ဖန တ ပ သ ပ ပ.. အကယ လ ႔ က ယ ႔အ နန ႔အစကတည က SQL statement က ပ သ ပ ဖန တ မယ ဆ ရင လ ရပ တယ.. ခ နက moemyintshein ဆ တ ႔န မည န ႔localhost ဆ တ ႔က န တ ႔Server မ user အသ စ ဖန တ ထ တ ႔အတ က အခ တ စ ခ တ ႔SQL statement က သ ပ username က moemyintshein1 password က moemyint12345 လ ႔ ပ ပ အသစ ထ ပ ဖန တ ပ မယ ခင ဗ 76 Youth Dreams 76

77 အထက ပ ပ အတ င PHP Admin main page ရ ႕ည ဘက ထ င အ ပၚန လ မ button င ခ ရ တ ႔အနက အလယ က SQL ဆ တ လ က ပ လ က တ ႔အခ သ ႔ အ က မ SQL query က execute လ ပ င တ ႔pop up page တ စ ခ တတ လ ပ တယ.. အ ဒ အထ မ က န က GRANT ALL ON *.* TO IDENTIFIED BY "moemyint12345"; လ ႔ရ က ပ Go က ပ လ က တ ႔အခ localhost ဆ တ ႔Server မ moemyint12345 ဆ တ ႔password န ႔moemyintshein1 ဆ တ ႔user အသ စ တ စ ယ က က လ ည ထပ ဖန တ လ က ပ ဖစ ပ တ ယ အခ အခ န မ privileges ထ မ ၀င ၾက ည တ ႔အခ အ က ပ တ င အစက root ပ ရ ရ က န user အသ စ စ ယ က ပ ရ နမ ဖစ ပ တ ယ.. user အသစ ဖန တ ပ တ ႔ န က မ PHP MyAdmin ထ မ Table ဆ က ရ အ င ဗ Database အရင ဆ က ဖ ႔လ ပ တယ Home ပ စ လ က ပ လ က ရင Databases ဆ တ သ ႔ရ ႕ menu တ ထ မ ရ လ ႔ တ ႔ပ တ ယ အ ဒ မ Create New Database ဆ တ ႔ အ က လ မ ဆ က င ပ တယ Database န မည က mydomain လ ႔ ပ လ က ပ တယ Collation ဆ တ ႔အထ မ တ ႔အဆ င ပမ က ပ ပ ႔ က န က utf8_general_ci န ႔ ဆ က လ က တ ယ ပ တ ႔ န က မ အ က ပ ပ အတ င ပၚလ ပ တ ႔က န က mydomain ဆ တ ႔အ ဒ database ထ မ people ဆ တ ႔table က field လ ခ ပ ပ Go က ပ ပ ဆ က လ က ပ တယ 77 Youth Dreams 77

78 Go က ပ ပ ဆ က လ က တ ႔အခ mydomain ဆ တ ႔database ထ မ people ဆ တ ႔table ရ က နပ ပ အ က ပ အတ င ဖည ပ table က save လ ပ လ က ပ မယ PHP MyAdmin ထ မ တ ႔အခ လ သ ဖည မယ 78 Youth Dreams 78

79 ဒ အတ င တ ဖည ပ တ ႔save လ က ပ တ ယ length value က input character တ ရ ႕လက အခ င ဆ အရ ည က သတ မ တ ပ တ ဖစ ပ တ ယ Type အတ က ထ လ ႔ ရတ တ က လည အမ ၾက ပ က န ဒ မ လ က ထ ည ထ တ ပ efficient ဖစ ခ င မ ဖစ မယ PHP MyAdmin ရ ႕ function တ စ ခ ႕က အ ခခ လ က သ တ တ အ င ဒ ဟ က ထည ပ ထ တ ပ ပ ရင Drop က သ ပ အခ န မ ရ ဒ table တ ဖ က လ ႔ရပ တယ Primary Key အ နန ႔သ မယ ႔id fileld က auto_increment ပ ထ ပ တ ယ record တ က Input ထပ ထည တ ႔အခ က န တ ႔ရ က ရ က နစရ မလ တ ႔ဘ ပ ႔ Default က တ ႔0 ပ လ က ပ တယ အ တန ဖ တ အ လ ထည ပ save လ ပ လ က တ ႔ အ က ပ screen ပၚလ ပ တယ 79 Youth Dreams 79

80 သင table ဖန တ တတ ပ ပ အ ဒ table က ဖစ စတ ႔SQL command တ က လ ည တ ႔ရမ ပ အခ တ ႔သ င သ ခ င မ သ ပ လ မ ႔မယ ဒ ပမယ ႔ ဘယ ဟ က ဘ က ဆ လ တ ယ ဆ တ PHP Database အခန က လ ႔လ လ ရင တ ႔ သ ဘ ပ က လ မ ပ Table ထ က Data တ ထည ရ အ င ဗ Insert ဆ တ အ ပၚမ တ ႔မယ ထင ပ တ ယ ပ လ က ၾက ရ အ င ပ တ ႔အခ အခ လ ပ ဖည ထ ည င ပ တ ယ သ ႔ရ ႕အ ပၚမ ရ တ ႔tab တ က လ က သ ပ ၾကည ပ 80 Youth Dreams 80

81 Insert က ပန ပ ပ ဒတ တ field တ စ ခ စ အတ က ထ ပ ထပ ဖည သ င ပ တယ အ က န လ မ သ ႔setting တ ခ န လ ႔ရတ ရ ပ တယ တခ ဖည ပ လ ႔save လ ပ တ င SQL code တ ပ တ ႔window လည ပၚလ ပ တ ယ id column က auto increment ဖစ တ ႔အတ က ဘ မ မထည ပ ပ ဘ အ က ပ ပ စ အတ င ဖစ သ အ င ဖည ပ ၾကည ပ လ အ လ ဖစ ပ လ မ ဖစ သ ဘ လ ဆ တ Browse Tab က ၀င ပ ၾက ည င ပ တယ ခင ဗ အ ဒ မ ဘ န က ခ တ ပ န ႔ ဟ လ က တ စ ခ ခ င ဆ က edit ပ လ ပ ပ တ ႔အမ က ပ လ က တ ႔Delete ပ လ ပ တ လ ပ အခ ဘ ယ လ back up လ ပ လ လ႔လ ရ အ င Database ထ က သ ရ အ င ဒ ဘက ဘယ ဘက ပ ႔အခ database က တ ႔mydomain ပ ႔ အ ပၚက Tab တ ထ က Export က ရ မယ 81 Youth Dreams 81

82 အခ က တ ႔people တ စခ ပ ဆ က ထ တ ႔သ ပ ရ တ ယ အ ဒ အက က လ ထ မ export လ ခ င တ ႔backup လ ပ ခ င တ ႔ table တ က ထ ပ ရ င တ ယ က န က တ ႔ ပ တ ႔အခ save as file က checked လ ပ ပ တ ႔zipped က ထ ပ ရ ပ တ ႔GO လ ပ လ က ပ တ ယ အ ဒ အခ ဒ င လ ပ ဆ ရပ ပ mydomain.sql ဆ တ ႔ဖ င လ က Zip န ႔ရပ တယ ခင ဗ အ ဒ backup ပ ပ အခ လ က ဆ လ ႔လ သ အ နန ႔Database ဆ က တ တ ပ table တ ဆ က တတ ပ fileds တ ဖန တ တတ ပ records တ ထ အခ က အလက ထည တတ တယ record က ပန ၾကည တတ တယ edit လ ပ တတ တယ ဖ က တတ တယ န က ဆ back up ပ လ ပ တတ ပ ပ အ ဒ အ ခခ ပ ပ က န တ တ က တ ဖည ဖည န ႔ဆက လ႔လ သ ပ ခင ဗ က န က တ ႔ဒ လ က ပ အစ ပ ပ လ က ပ တ ယ 82 Youth Dreams 82

83 Chapter 8.PHP and Database ကၽ န တ တ ႔အ နန ႔တက ယ ဆ PHP, My SQL Database န ႔Apache Web Server တ ႔က တစ ခ စ သ သ န ႔ သ င ပ ခ တ ဆ က အသ ပ သ င ပမယ ႔ဒ စ အ ပ ရ ႕ ရည ရ ယ ခ က က မန မန န ႔လ ယ လ ယ PHP ရ ႕အ ခခ တ က န လည စခ င တ ဖစ တ ႔အတ က XAMPP က သ အဆင သ င Install လ ပ ပ လ ႔လ ၾက တ ဖစ ပ တ ယ.. သင ခန စ တ မ လ ယ က စဖ ႔အတ က က န တ ႔ရ ႕PHP က လ ႔လ ရ မ အသ ပ နတ ႔XAMPP န ႔သ ႔ရ ႕တ ပ တ ႔ PHP Myadmin စတ ႔tool တ န ႔ပ တ သ တ ပ အ ရ ႕က အခန မ အနည ငယ လ႔လ ခ ႔ ပ ဖစ ပ တ ယ PHP Database PHP MySQL Introduction What is MySQL? MySQL ဆ တ က တ ႔ ပၚပ လ အ ဖစ ဆ open source database system ပ ဖစ ပ တ ယ MySQL ဆ တ database ပ MySQL ထ မ ဒတ တ က tables လ ႔ ခၚတ ႔database objects တ ထ မ သ မ ဆ ည ပ တ ယ table ဆ တ က တ ႔ ဆက ယ နတ ႔ ဒတ တ စ ပ င ပ ၀င တ ႔column တ rows တ ပ ၀င တ ႔အစ အ ၀ တ စ ခ ပ အခ အခ န မ Database ရ ႕အ ခခ လ နည နည က န လ ည အ င ၾကည ၾက ရ အ င လ.. Database Tables database တ စ ခ မ table တစ ခ ဒ မ မဟ တ အမ ၾက ပ ၀င ပ တ ယ table တ စ ခ စ မ အမည ရ ပ မယ ဥပမ (Customers, Orders). Table တ မ rows လ ႔ ခၚတ ႔records တ ပ ၀င ပ တယ အ က က ဥပမ က တ ႔Persons လ ႔ ခၚတ ႔table ရ ႕ ဥပမ လ ပ ဒ table မ ဆ ရင လ တစ ယ က အတ က တ စ ခ စ စ ပ င သ ခ records (rows) သ ခ န ႔column(LastName, firstname, Address န ႔City) ဆ ပ တ ႔ လ ခ ပ ၀င ပ တ ယ Queries query ဆ တ က တ ႔ မ ခ န ဒ မ မဟ တ တ င ဆ မ လ ႔ ပ င ပ တ ယ အ က က query လ က ၾကည ပ SELECT LastName FROM Persons ဒ query လ က Persons table ထ က LastName ဆ တ ႔column ထ က အခ က အလ က တ အ လ က ရ ထ တ ပ မ ဖစ ပ တ ယ အ က က ပ စ အတ င ထ က လ ပ မယ Create a Connection to a MySQL Database 83 Youth Dreams 83

84 database တ စ ခ ထ က data တ access မလ ပ င ခင မ ပ database အတ က connection က ဖန တ ပ ရပ မယ PHP မ တ ႔mysql_connect() function က သ ပ လ ပ င ပ တ ယ Syntax mysql_connect(servername,username,password); အ က က code ထ မ ဆ ရင က န တ ႔အ နန ႔connection က ($con) ဆ တ ႔variable လ ထ မ သ မ ပ တ ယ.. script ထ မ န က ပ င မ ပန လ ည ခၚအသ ပ ဖ ႔အတ က ပ အက ယ connection fail ဖစ ခ ႔ရင တ ႔die က အလ ပ လ ပ ပ မယ $con=mysql_connect("localhost","user","password"); if (!$con) die('could not connect:' > mysql_error()); //some code PHP Script ဆ သ တ ႔အခ မ connection အလ အ လ က ပ တ သ ပ တယ ၾက ပ တ ခ င ရင တ ႔mysql_done() fucntoin က သ င ပ တ ယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); // some code mysql_close($con); PHP MySQL Create Database and Tables Create a Database MySQL မ database တစ ခ က ဖန တ ဖ ႔အတ က CREATE DATABASE statement က အသ ပ ပ တ ယ Syntax CREATE DATABASE database_name အခ က PHP tutorial ဖစ တ ႔အ တ က လ အ ပ သ လ က database အပ င က ပ ရ မ ဖစ ပ တယ.. တ တ င သ လ က တ ႔ SQL က လ ည ထည ရ ပ ထ ပ တယ သ ခ SQL က ထပ လ ႔လ င ရင လည က င ပ တ ယ 84 Youth Dreams 84

85 အထက ပ စ ၾက င က execute လ ပ ဖ ႔အတ က mysql_query() function က အသ ပ ရပ မယ ဒ function က တ ႔ MySQL connection ဆ က query ဒ မ မဟ တ command တ စ ခ ပ ႔ဖ ႔အတ က အသ ပ ရတ ပ အ က ပ ဥပမ က တ ႔my_db လ ႔ ခၚတ ႔database တစ ခ က ဖန တ တ ပ $con = mysql_connect("localhost","user","moemyintshein"); if (!$con) die('could not connect: '. mysql_error()); if (mysql_query("create DATABASE my_db",$con)) echo "Database created"; else echo "Error creating database: ". mysql_error(); mysql_close($con); Table တစ ခ တည ဆ က ခင CREATE TABLE statement က သ ပ တ ႔MySQL မ table တစ ခ က တည ဆ က ရပ တယ သ ႔ရ ႕syntax က တ ႔ CREATE TABLE table_name ( colomn_name1 data_type, colomn_name2 data_type, column_name3 data_type, ) အခ လ ပ စ ပ ဖစ ပ တ ယ SQL အ ၾက င သင ခ င ရင SQL Tutorial က လ႔လ ပ ခင ဗ PHP ထ မ ထည သ ဖ ႔အတ က mysql_query() function ထ က CREATE TABLE statement က ပ င ထ ည ပ execute လ ပ မ ဖစ ပ တ ယ ဥပမ အ က ပ ဥပမ မ Persons ဆ တ ႔table တ စ ခ က ဖန တ ပ တ ႔သ ႔မ FirstName, LastName န ႔Age ဆ တ ႔Colomn သ ခ ပ ၀င မ ဖစ ပ တယ $con = mysql_connect("localhost","root","moemyintshein"); if (!$con) 85 Youth Dreams 85

86 die('could not connect: '. mysql_error()); // Create database if (mysql_query("create DATABASE my_db1",$con)) echo "Database created"; else echo "Error creating database: ". mysql_error(); // Create table mysql_select_db("my_db1", $con); $sql = "CREATE TABLE Persons ( FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql,$con); mysql_close($con); မ တ သ ရန - table တစ ခ က မဖန တ ခင မ database က ရ ပ ရပ တ ယ mysql_select_db() ဆ တ ႔function က သ ပ တ ႔database က ရ ပ င ပ တ ယ varchar type က သ ပ တ ႔database field တ စ ခ က ဖန တ တ ႔အခ မ အ ဒ filed ရ ႕maximum length ဥပမ varchar(15) ဆ ပ တ ႔သတ မ တ ပ ရပ မယ data type က န ပ တ ႔ဒ column ကက င တ ယ င တ ႔data အမ အစ က သတ မ တ ပ တ ဖစ ပ တယ Primary Keys and Auto Increment Fields table တစ ခ ထ မ ရ တ ႔rows တ က ခ ခမ စ တ ဖ င ဖ ႔အတ က primary key တ စ ခ က အသ ပ ရပ တ ယ primar y key တစ ခ စ ဟ table ထ မ တစ ခ ထည ရ ရပ မယ primary key ဟ null (ဘ မ မရ တ ႔တ န ဖ ) မ ဖစ ရပ ဘ ဘ ဖစ လ ႔လ ည ဆ တ ႔database engine အ နန ႔record တ က ရ ဖ ဖ ႔အတ က တ န ဖ တ စ ခ ခ တ ႔လ အပ တ ႔အတ က ဖစ ပ တ ယ အ က ပ ဥပမ မ personid ဆ တ ႔field က primary key filed အ နန ႔ထ တ ဖစ ပ တ ယ primary key filed တ ဟ အမ အ ဖင ID number ဖစ ၾက ပ တ ႔AUTO_INCREMENT setting က အသ ပ ထ တ တ မ ပ တ ယ AUTO_INCREMENT ဆ တ က တ ႔record (column) တ စ ခ က အသ စ ပ င ထ ည တ င မ အ ဒ primary 86 Youth Dreams 86

87 key အ ဖစ သတ မ တ ထ တ ႔field ထ ကတန ဖ က အလ အ လ က တစ ပ င ပ တ က ပ တ ပ primary key filed က null မ ဖစ တ သ ခ စဖ ႔အတ က ဒ field အတ က NOT NULL ဆ တ ႔setting က ထည ပ ထ ၾက ရပ တ ယ $sql = "CREATE TABLE Persons ( personid int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID), FirstName varchar(15), LastName varchar(15), Age int )"; mysql_query($sql,$con); PHP MySQL Insert Into INSERT INTO statement က table တစ ခ ထ က column(record) အသ စ တ ထ ပ ပ င ထ ည ဖ ႔အတ က အသ ပ ပ တ ယ Syntax INSERT INTO statement က ပ စ စ မ န ႔ ရ င ပ တယ ပထ မပ စ က တ ႔data တ က ပ င ထ ည မယ ႔ နရ column န မည တ က မ ဖ ပဘ န ႔သ တ ႔ရ ႕တ န ဖ တ က ပ ထ ည တ ႔ ပ စ ပ INSERT INTO table_name VALUES (value1, value2, value3,...) ဒ တ ယပ စ က တ ႔column name ရ ထ ည မည တန ဖ ရ က စ ခ စလ ဖ ပသတ မ တ ပ တ ႔ အ က ပ ပ စ ပ INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) PHP က အသ ပ ပ တ ႔ ဒ statement တ က execute လ ပ င ဖ ႔အတ က mysql_query() function က အသ ပ ၾက ရပ မယ ဒ function က MySQL connection တစ ခ ဆ က query တ စ ခ ဒ မ မဟ တ command တ စ ခ ပ ႔ဖ ႔အတ က အသ ပ ၾကရပ တ ယ ဥပမ အ ရ ႕မ က န တ ႔Persons လ ႔န မည ပ ထ တ ႔table တစ ခ က Firstname, Lastname န ႔Age ဆ တ ႔Column သ ခ န ႔ ဖန တ ခ ႔ၾကပ တယ ဒ ဥပမ မ အ ဒ table က ပ ပန အသ ပ ပ မယ ဒ မ ဒ Persons ဆ တ ႔table ထ က ပ record အသစ စ ခ က အ က ပ အ တ င ပ င ထ ည လ က ပ မယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) 87 Youth Dreams 87

88 die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); mysql_query("insert INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("insert INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')"); mysql_close($con); Insert Data From a Form Into a Database အခ က န တ ႔Persons table ထ က record အသ စ တ ပ င ထ ည ပ င မယ ႔HTML form တစ ခ က ဖန တ ပ မယ အ က က တ ႔HTML form ပ <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> user က ဒ ဥပမ ထ က HTML form ထ မ ပ တ ႔Submit button က ပ လ က တ ႔အခ form ထ မ ထည ထ တ ႔data တ က insert.php ဆ က ပ ႔ ပ မ ပ insert.php ဖ င က န database တစ ခ ဆ က ဆက သ ယ ပ မယ ပ တ ႔PHP $_POST variables တ က သ ပ form ထ က တန ဖ တ က ထ တ ယ မ ဖစ ပ တယ အ ဒ န က မ တ ႔mysql_query() function က န ပ တ ႔INSERT INTO statement က အလ ပ လ ပ သ မ ဖစ ပ Persons table ထ က record အသစ တ စ ခ ထပ ပ င ထည ပ မ ဖစ ပ တ ယ insert.php အတ က code ပ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $sql="insert INTO Persons (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) die('error: '. mysql_error()); echo "1 record added"; mysql_close($con) 88 Youth Dreams 88

89 PHP MySQL Select Select Data From a Database Table SELECT statement က database တစ ခ ထ က နdata က select လ ပ ဖ ႔အတ က အသ ပ ပ တယ Syntax SELECT column_name(s) FROM table_name ထ စ အတ င PHP န ႔အလ ပ လ ပ ဖ ႔အတ က mysql_query() function က က န တ ႔သ ၾကရပ မယ ဥပမ အ က ပ ဥပမ မ Persons table ထ မ သ မ ထ တ ႔data တ အ လ က ထ တ တ ပမ ဖစ ပ တ ယ * ဆ တ ႔character လ က table ထ မ ရ တ ႔data တ အ လ က ရ ခ ယ ထ တ ပ ပ တယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("select * FROM Persons"); while($row = mysql_fetch_array($result)) echo $row['firstname']. " ". $row['lastname']; echo "<br />"; mysql_close($con); အထက ပ ဥပမ မ mysql_query() က န return ပန လ တ ႔data တ က $result ဆ တ ႔variable ထ မ သ မ ဆည ထ ပ တ ယ အ ဒ န က မ array အ နန ႔recrodset ထ က ပထ မဆ row က return ပန ဖ ႔အတ က mysql_fetch_array () function က အသ ပ ထ ပ တယ mysql_fetch_array() က ခၚသ တ င မ recordset ထ မ ရ တ ႔ န က ထ ပ န က ထပ row တ က return ပန ပ ပ တ ယ while loop က န recordset ထ က record တ အ လ က ဖတ သ ပ Looping ပတ ပ တ ယ row တ စ ခ စ ရ ႕ တ န ဖ တ က Screen မ Print ထ တ ပ ပ ဖ ႔အတ က PHP $row variable ($row['firstname'] and $row['lastname']) က က န တ ႔အသ ပ ထ ပ တယ ဒ code ရ ႕Output အ နန ႔ အ က ပ အတ င ထ က လ မ ဖစ ပ တယ 89 Youth Dreams 89

90 Peter Griffin Glenn Quagmire Display the Result in an HTML Table အ က ပ ဥပမ အ နန ႔က တ ႔အထ က ပ ဥပမ အတ င ပ တ ည တ ႔data တ က ထ တ တ မ ဖစ ပ တယ ဒ ပမယ ႔ သ က တ ႔HTML tab;e တစ ခ န ႔data တ က ထ တ ပ ပ သ မ ဖစ ပ တယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("select * FROM Persons"); echo "<table border='1'> <tr> <th>firstname</th> <th>lastname</th> </tr>"; while($row = mysql_fetch_array($result)) echo "<tr>"; echo "<td>". $row['firstname']. "</td>"; echo "<td>". $row['lastname']. "</td>"; echo "</tr>"; echo "</table>"; mysql_close($con); အထက ပ code တ ရ ႕output က တ ႔ အ က ပ အတ င ဖစ ပ လ မ ႔မယ PHP MySQL The Where Clause WHERE clause က တ ႔သ တ မ တ ထ တ ႔အ ခအ နတစ ခ က ပည စ စတ ႔record တ က ပ ထ တ ပဖ ႔အတ က အသ ပ ၾကရပ တယ 90 Youth Dreams 90

91 Syntax SELECT column_name(s) FROM table_name WHERE column_name operator value ဥပမ အ က ပ ဥပမ မ Persons table ထ က FirstName က Peter ဖစ နတ ႔row တ အ လ က ထ တ တ ပ ပ ပ လ ႔ ဖ ပ ထ ပ တယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("select * FROM Persons WHERE FirstName='Peter'"); while($row = mysql_fetch_array($result)) echo $row['firstname']. " ". $row['lastname']; echo "<br />"; output အ နန ႔က တ ႔- Peter Griffin ဆ ပ တ ႔ရပ မယ ခင ဗ PHP MySQL Order By Keyword ORDER BY keyword က တ ႔recordset တ စ ခ ထ က data တ က စ ထ ဖ ႔အတ က အသ ပ ပ တ ယ ORDER BY keyword လ က default အ နန ႔ascending order န ႔record တ က စ ပ ပ တ ယ descending order န ႔record တ က စ မယ ဆ ရင DESC keyword က ထ ည သ င အသ ပ င ပ တ ယ Syntax SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC DESC ဥပမ 91 Youth Dreams 91

92 အ က ပ ဥပမ မ Persons table ထ မ သ မ ထ တ ႔data တ အ လ က ထ တ ပ ပ ပ တယ ပတ ႔ နရ မ Age column န ႔result တ က စ ထ ပ တ ဖစ ပ တ ယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("select * FROM Persons ORDER BY age"); while($row = mysql_fetch_array($result)) echo $row['firstname']; echo " ". $row['lastname']; echo " ". $row['age']; echo "<br />"; mysql_close($con); ဒ code ရ ႕output က တ ႔ Glenn Quagmire 33 Peter Griffin 35 ဖစ ပ တ ယ Order by Two Columns column တစ ခ မက သ ပ တ ႔လ ည order by လ ပ င ပ တယ တ စ ခ ထက ပ တ ႔column တ န ႔Ordering လ ပ မယ ဆ ရင တ ႔ပထမcolumn ကတ န ဖ တ တ ည နမ သ ဒ တ ယ column က အသ ပ ပ တယ SELECT column_name(s) FROM table_name ORDER BY column1, column2 PHP MySQL Update UPDATE statement က တ ႔table တစ ခ ထ က ရ န ပ သ record တ က ပင ဆင ရန Update လ ပ ရန အသ ပ ပ တ ယ Syntax UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value 92 Youth Dreams 92

93 ဒ မ အ ရ ၾက တ က WHERE clause ပ ဖစ ပ တ ယ UPDATE syntax က အသ ပ တ ႔ခ WHERE clause အ နန ႔ဘယ record တ က ပင ဆ င မ လ ည ဆ တ က သ တ မ တ ပ ရတ ဖစ ပ တယ WHERE မပ ဘ သ မယ ဆ records တ အ လ Update တ ဖစ က န မ ဖစ ပ တယ ဥပမ က န တ ႔ဖန တ ခ ႔တ ႔Persons ဆ တ ႔Table မ အ က ပ အတ င ရ နတ ပ.. အ က ပ ဥပမ လ က Persons table ထ မ ရ တ ႔data တ စ ခ ႕က update လ ပ ပ ပ တယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); mysql_query("update Persons SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'"); mysql_close($con); Update လ ပ ပ တ ႔အခ မ Persons table ထ မ အ က ပ ပ စ အတ င ဖစ သ ပ တ ယ PHP MySQL Delete DELETE statement က database table ထ က records တ က ဖတ ဖ ႔အတ က အသ ပ ပ တယ FROM ဆ ပ တ ႔ DELETE ရ ႕ န က မ ပ ပ တ ယ Syntax DELETE FROM table_name WHERE some_column = some_value သ ႔မ လည အ ရ ၾက တ က WHERE clause ပ ဖစ ပ တယ WHERE clause အ နန ႔ဘယ record တ က ဖတ မယ မ လ ည ဆ တ က သ တ မ တ ပ ရတ ဖစ ပ တယ WHERE မပ ဘ သ မယ ဆ records တ အ လ Delete တ ဖစ က န မ ဖစ ပ တယ 93 Youth Dreams 93

94 ဥပမ အစတ န က Persons table က ဒ လ ရ ပ မယ အ က က code တ က သ ပ တ ႔LasteName က Griffin ဖစ တ ႔Persons table ထ က record တ က ဖ က ပ လ ႔ ပ လ က ပ မယ $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('could not connect: '. mysql_error()); mysql_select_db("my_db", $con); mysql_query("delete FROM Persons WHERE LastName='Griffin'"); mysql_close($con); Delete လ ပ ပ တ ႔အခ မ တ ႔ အ က ပ အတ င ဖစ သ ပ မယ PHP Database ODBC ODBC ဆ တ က တ ႔Microsoft Access Database လ မ Data Source တစ ခ က ဆက သ ယ ပ မယ ႔Application Programming Interface (API) ဖစ ပ တယ Create an ODBC Connection ODBC connection တ စ ခ န ႔က န တ ႔အ နန ႔ ODBC connection တစ ခ ရ နသ ရ ႕က န တ ႔နတ ၀က ထ မ ရ တ ႔ ဘယ က န ပ တ ပၚမ ပ ဖစ ဖစ ရ တ ႔ဘ ယ database န ႔မဆ ခ တ ဆတ အသ ပ င ပ တယ အ က ပ ဖ ပခ က တ ႔MS Access Database တ စ ခ န ႔ODBC Connection တစ ခ ဘ ယ လ ဖန တ တယ ဆ တ ပ 1. Open the Administrative Tools icon in your Control Panel. 2. Double-click on the Data Sources (ODBC) icon inside. 3. Choose the System DSN tab. 94 Youth Dreams 94

95 4. Click on Add in the System DSN tab. 5. Select the Microsoft Access Driver. Click Finish. 6. In the next screen, click Select to locate the database. 7. Give the database a Data Source Name (DSN). 8. Click OK. ဒ configuration က website ရ နတ ႔က န ပ တ ပၚမ ပ လ ပ ရမ ဖစ ပ တ ယ က န တ ႔ရ ႕က န ပ တ မ Internet Information Server ဆ တ ႔IIS က run ထ မယ ဆ ရင ဒ instruction တ က အလ ပ လ ပ မ ဖစ ပ တ ယ remote server ပၚမ က န တ ႔ရ ႕website ရ တ ဆ ရင တ ႔အ ဒ server က Physical access ရ ရပ မယ ဒ မ မဟ တ web host က က န တ ႔အသ ပ ရမယ ႔DNS တ စ ခ က set up လ ပ ပ ဖ ႔ တ င ခ ရပ မယ Connecting to an ODBC odbc_connect() function က ODBC data source တ စ ခ န ႔ခ တ ဆ က ဖ ႔အတ က သ ပ တယ ဒ function မ parameter လ ခ ရ ပ တယ data source န မည ရယ username ရယ Password ရယ န ႔Optical cursor type ဖစ ပ တယ SQL statement တ က execute လ ပ ဖ ႔အတ က odbc_exec() function က အသ ပ ပ တ ယ ဥပမ အ က ကဥပမ မ northwind လ ႔ ခၚတ ႔DNS တ စ ခ က connection ဖန တ ပ တ ယ username န ႔password န ႔ northwind မ မရ ပ ဘ အ ဒ န က SQL တစ ခ က ဖန တ ပ တ ႔execute လ ပ ပ တ ယ $conn=odbc_connect('northwind','',''); $sql="select * FROM customers"; $rs=odbc_exec($conn,$sql); Retrieving Records odbc_fetch_row() က သ ပ တ ႔result-set က န record တ က return ပန ပ တယ ဒ function က rows တ က return ပန င တယ ဆ ရင true လ ႔ ပ ပ တ ႔ဒ မ မဟ တ ရင တ ႔false ပ ပ တယ ဒ function က တ ႔ODBC result identifier န ႔Optical row number ဆ တ ႔parameter စ ခ က ယ ပ တယ odbc_fetch_row($rs) Retrieving Fields from a Record odbc_result() function က record တ စ ခ က န fields တ က ဖတ ဖ ႔အသ ပ ပ တ ယ ဒ function က ODBC result identifier န ႔field number ဒ မ မဟ တ name တ စ ခ စ စ ပ င parameter စ ခ က ယ ပ တယ. အ က က code line မ တ ႔record ထ က ပထမဆ field ရ ႕တ န ဖ က return ပန ပ ပ တ ယ $compname=odbc_result($rs,1); 95 Youth Dreams 95

96 အ က က code line က တ ႔CompanyName လ ႔ ခၚတ ႔field တ စ ခ ရ ႕တ န ဖ က return ပန ပ ပ တ ယ $compname=odbc_result($rs,"companyname"); Closing an ODBC Connection odbc_close() function က သ ပ ODBC connection တ စ ခ က ပ တ ရပ မယ odbc_close($conn); ODBC ဥပမ အ က ပ ဥပမ မ database connection တစ ခ က အရင ဆ ဘယ လ ဖန တ တ ယ ပ တ ႔result set တ စ ခ န ႔HTML table တစ ခ ထ မ data တ က ပ ပ ဖ ႔အတ က ရ တ က ပထ ပ တယ <html> <body> $conn=odbc_connect('northwind','',''); if (!$conn) exit("connection Failed: ". $conn); $sql="select * FROM customers"; $rs=odbc_exec($conn,$sql); if (!$rs) exit("error in SQL"); echo "<table><tr>"; echo "<th>companyname</th>"; echo "<th>contactname</th></tr>"; while (odbc_fetch_row($rs)) $compname=odbc_result($rs,"companyname"); $conname=odbc_result($rs,"contactname"); echo "<tr><td>$compname</td>"; echo "<td>$conname</td></tr>"; odbc_close($conn); echo "</table>"; </body> </html 96 Youth Dreams 96

97 Chapter 9. XML & PHP က န တ ႔အတ က Web Development န ႔ပတ သ က ရင XML ဆ တ မသ မ ဖစ ပ ဖစ ပ တယ XML ဆ တ Extensible Markup Language ဖစ ပ တ ယ XML က data သယ ဆ င ဖ ႔န ႔သ မ ဆ ည ဖ ႔ဖန တ ထ တ ဖစ ပ တ ယ ဒ က တ ရ ရယ မ XML အ ခခ က ဖ ပ ပ မ ဖစ ပ တ ယ HTML န ႔XML န ႔ဘ တ က ခ သလ ဆ တ မ တ လ ည ရ င သ ပ မယ XML က သ ဖ ႔အ ရ ၾက ပ တယ သင ယ ဖ ႔လည လ ယ က ပ တ ယ Introduction to XML XML က data သ ယ ဆ င ဖ ႔န ႔သ မ ဆ ည ဖ ႔တ ထ င ထ တ ဖစ ပ တ ယ HTML က တ ႔Data တ က ထ တ ပဖ ႔အတ က ဖစ ပ တ ယ XML က HTML လ မ ပ အ တ လ တ တ ႔markup language ပ ပ XML tags တ က ၾက တ င သ တ မ တ ထ တ ႔predefined တ မဟ တ ပ ဘ.. က န တ ႔က ယ ႔ဘ က ယ သတ မ တ ပ ရ ပ မယ XML က self-descriptive ပ စ ဖစ ပ တယ XML က W3C က နလ ည ထ က ခ မ ပ ထ ပ တ ယ XML န ႔HTML တ ႔ရ ႕ ခ န ခ က တ က သ ရပ မယ XML က HTML နရ က အစ ၀င တ မဟ တ ပ ဘ သ တ ႔ စ ခ က မတ ည တ ႔ရည ရ ယ ခ က တ န ႔ ပၚလ ၾက တ ပ XML က data တ က သ ယ ဆ င ဖ ႔န ႔သ မ ဆ ည ဖ ႔ ဖစ ပ တယ.. ဘ ဒတ တ လည ဆ တ ႔အ ပၚမ ဥ တ ည ပ တယ HTML က တ ႔ဒ ဒတ တ က ဘ ယ လ ပ စ ရ လ ဆ တ ႔အ ပၚမ မ တ ည ပ တ ႔data တ က ပသ ဖ ႔အတ က ပ HTML ကအခ က အလက တ က ထ တ ပဖ ႔ ဖစ ပ XML က တ ႔ အခ က အလ က တ သယ ဆ င သ မ ဆည ဖ ႔ ဖစ တယ လ ႔န လည ရပ မယ XML Does not DO Anything XML က ဘ က မ မလ ပ ပ င ပ ဘ န လ ညဖ ႔ခတ ပ မယ တ ကယ တ ႔XML က တ စ စ တစ ရ က မ ပ လ ပ ပ ဘ အခ က အလ က တ က ဖ ႔စည တ ည ဆ က သ မ ဆ ည ပ သယ ဆ င ဖ ႔ပ ဖစ ပ တ ယ အ က ပ ဥပမ က တ ႔XML န ႔သ မ ဆ ည ထ တ ႔Jani က နTove ဆ က ပ တ ႔note တစ ခ ဖစ ပ တယ <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> က ဒ တ က က ယ န လ ည အ င က ယ ႔ဘ က ရ ထ တ ဖစ ပ တယ self descriptive သ ဘ တ ရ ပ သ ႔မ ပ ႔တ ႔သ န ႔ လက ခ တ ႔သ ရ ႕အခ က အလ က တ ပ ပ တယ သ ႔မ ခ င စဥ ပ သ လ စ က ယ လ ည ပ ၀င ပ တ ယ မ န ပ တ ယ ဒ ပမယ ႔ဒ XML document လ က တ စ စ တ စ ရ က အလ ပ မလ ပ ဘ လ.. tags တ န ႔ ရ ထ တ ႔ အခ က အ လက ရ င ရ င လ မ သ ပ ဖစ ပ တ ယ တစ စ တ စ ယ က က Software တစ ခ န ႔ခ တ ဆ က ပ ဒ အခ က အလက တ က ပ ႔ ပ ဖ ႔ လက ခ ဖ ႔ ပသဖ ႔လ ပ ဆ င ရရမ ဖစ ပ တယ XML is Just Plain Text 97 Youth Dreams 97

98 XML က ဘ မ မထ ခ ပ ဘ စ တ သက သက ခ ည ပ ဖစ ပ တယ plain text တ က က င တ ယ င တ ႔Software တ က XML က လ ည က င တ ယ င ပ မယ ဒ ပမယ ႔XML အတ က ဥ စ ပ Application တ က တ ႔XML tag တ က က င က င က င တ ယ င ပ တ ယ ဒ tags တ ရ ႕ဘ က လ ပ ဆ င တယ ဆ တ ႔အဓ ပ ယ က တ ႔application ရ ႕ သ ဘ သ ဘ ၀ ပၚမ မ ခ ပ မယ XML က အသ ပ ပ တ ႔က န တ ႔က က ယ ၾက က တ ႔က ယ ပ င tag က ဖန တ င ၾက ပ တယ အ ပၚက ဥပမ က <to> တ ႔ <from> တ ႔လ ပ ႔ အ ဒ တ ဟ ဘယ XML standard မ မ defined လ ပ ထ တ မရ ပ ဘ ဒ tag တ က ဒ XML document က ရ သ တ ႔စ ရ ဆ ရ ကတ ထ င လ က တ ပ ပ ဒ ဟ ဘ ဖစ လ ႔လ ဆ တ ႔XML language မ predefined tags မရ လ ႔ပ ရ င သ အ င HTML န ႔ယ ဥ ပ မယ HTML မ သ တ ႔tag တ က တ ႔Predefined ပ HTML documents တ မ HTML standard သ တ မ တ ထ တ ႔ tags တ ဥပမ <p> <h1> အ ဒ မ တ က ပ အသ ပ င ပ တ ယ XML ဆ တ HTML ရ ႕အစ ထ မဟ တ ဘ အတ တက ပ ပ င လ ပ ဆ င ၾကတ သ ဖစ ပ တယ XML က သတ င အခ က အလက တ က သ ယ ဆ င ပ မယ ႔software န ႔hardware တ ပၚမ မ ခ မ မရ တ ႔အရ တစ ခ ဖစ ပ တယ XML က ရ သ တ ႔အခ သစ ပင တ စ ပင ရ ႕ ဖ ႔စည တ ည ဆ က မ အတ င အ မစ က နစ ပ တ ႔ သစ ရ က တ အထ ခ ဖ သ တ မ ဖစ ပ တ ယ XML document ဥပမ XML ဖ င တ စ ခ က self-describing ပ စ န ႔ ရ ပ တ ႔ရ ရ င တ ႔syntax တ က ပ အသ ပ ၾက ပ တ ယ <?xml version="1.0" encoding="iso " <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> ပထ မဆ စ ၾက င က တ ႔ဒ XML ဖ င ပ လ ႔ ပ လ က တ ပ XML version 1.0 ပ လ ႔ ဖ ပ ပ တ ႔အသ ပ ထ တ ႔ encoding က တ ႔(ISO = Latin-1/West European character set) ပ လ ႔ ၾက င လ က တ ပ န က ထပ တ စ ၾက င က တ ႔ဒ document လ ရ ႕root element က ဖ ပလ က တ ပ ဒ document လ က note တစ ခ ဖစ ပ တ ယ လ ႔ ပ လ က တ ပ ႔ <note> န က ထပ ပ လ တ ႔စ ၾက င လ ၾက င က တ ႔to,from,heading န ႔body ဆ တ ႔root ရ ႕child elements လ ခ က ဖ ပ ပ ပ တ ယ <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> န က ဆ စ ၾက င မ တ ႔root element ရ ႕အဆ သတ ပ ဆ ပ ပန ပ တ လ က တ ပ 98 Youth Dreams 98

99 </note> က န တ ႔အ နန ႔ဒ ဥပမ က န ဒ XML document ဟ ဆ ရင Jani က န Tove ဆ က note တစ ခ ပ ၀င တ ယ လ ႔ န လည င ပ တယ XML documents တ မ root element တစ ခ ပ ၀င က ပ ၀င ရပ မယ ဒ element က တ ခ element တ အ လ ရ ႕မ ဘ parent ဖစ ပ တ ယ XML တစ ခ မ ပ တ ႔elements တ က document tree တစ ခ လ ပ စ ဆ င ပ တ ယ သ စ ပင က root က နစ ပ တ ႔branches တ ထ ခ ဖ သ သလ ပ ႔ elements တ အ လ မ ထပ ခ တ ႔elements (child elements) တ ပ ၀င င ပ တ ယ <root> <child> <subchild>...</subchild> </child> </root> parent, child, sibling စတ ႔ ၀ ဟ ရ တ က elements တ ၾက ထ က ဆက ဆ မ အ ဖစ ဖ ပဖ ႔သ ပ တယ မ ဘ တ မ က လ တ ရ ပ မယ level တ က လ တ ဆ ရင မ င မည အစ မည အ စ က တ ပ ႔ elements တ အ လ မ HTML မ လ ပ text content န ႔attributes တ ပ ၀င င ပ တ ယ ဥပမ အထက ပ ပ က စ အ ပ တစ အ ပ က XML န ႔ အ က ပ အတ င ရ တ က က ယ စ ပ ပ တ ယ <bookstore> <book category="cooking"> <title lang="en">everyday Italian</title> <author>giada De Laurentiis</author> <year>2005</year> <price>30.00</price> 99 Youth Dreams 99

100 </book> <book category="children"> <title lang="en">harry Potter</title> <author>j K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">learning XML</title> <author>erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> ဒ ဥပမ ထ မ root element က <bookstore> ဖစ ပ တယ အ လ သ <book> elements တ က <bookstore> ထ မ ပ ၀င နပ တ ယ <book> element ထ မ က လ လ ယ က ရ ပ တ ယ <title> <author> <year> န ႔<price> တ ႔ ဖစ ပ တယ XML Syntax Rules XML Syntax Rules တ က ရ ရ င ပ ယ တ တန ပ တယ သင ယ ဖ ႔လ ယ က ပ တယ အသ ပ ဖ ႔အတ က လ ယ က ပ တယ အ လ သ elements တ မ အပ တ tag ပ ရပ မယ HTML မ ဆ ရင အပ တ မပ တ ႔elelement တ က ခဏ ခဏ မင ရပ လ မ ႔မယ အ က ကအတ င ပ ႔ <p>this is a paragraph <p>this is another paragraph XML မ က တ ႔closing tag က ထ ခ ႔လ ႔လ ႔ ၀မရပ ဘ အပ တ tag ရ က ရ ရပ မယ <p>this is a paragraph</p> <p>this is another paragraph</p> မ တ ခ က အ နန ႔အ ပၚက ဥပမ မ XML declaration စ ၾက င မ closing tag မပ ပ ဘ အ ဒ မ တ မဟ တ ပ ဘ.. declaration က XML document ရ ႕အစ တ အပ င တစ ခ မဟ တ ပ ဘ ဒ ၾက င အပ တ မပ ပ ဘ XML tags တ က Case Sensitive ဖစ ပ တ ယ XMLမ <letter> က <Letter> န ႔မတ ပ ဘ အပ တ န ႔အဖ င tag တ က တ ည တ ႔case န ႔ပ ရ သ ရပ မယ <Message>This is incorrect</message> <message>this is correct</message> XML elements တ က သ သ ခ ခ nested လ ပ ရပ မယ HTML မ ဆ ရင လ ပ ခ င သလ လ ပ လ ႔ရပ တ ယ ဥပမ bold န ႔ အရင ဖ င ထ ပ မ italic လ က ပ တ တ ႔အ ခ bold က အရင ပ တ ပ မ italic က ပ တ သ လ မ <b><i>this text is bold and italic</b></i> 100 Youth Dreams 100

101 XML မ က တ ႔အ ဒ လ မ ဖစ ရပ ဘ န က မ လ တ ႔ဟ အရင ပ တ ရပ မယ XML မ ဆ အ က က ပ စ မ န ႔ပ nested လ ပ က လ ပ ရပ မယ <b><i>this text is bold and italic</i></b> <i> က <b> ရ ႕အတ င ထ ရ က မ ဖ င တ ဖစ တ ႔အတ က <b> ရ ႕အတ င ထ မ ပ ပ တ က ပ တ ရပ မယ ဆ တ ႔သ ဘ ပ XML elements တ မ HTML လ မ ပ တ န ဖ အမည န မအစ လ က ပ တ ႔attributes တ ရ င ပ တ ယ attribute value တ က XML မ quote လ ပ ရပ မယ အ က က ပ စ စ မ က ၾကည ပ ပထမတစ မ က မ ပ တ ႔ဒ တ ယ လ ရ မ မ န ပ တယ <note date=12/11/2007> <to>tove</to> <from>jani</from> </note> ဒ ပထ မဟ မ မထည ထ လ ႔မ နပ တ ယ <note date="12/11/2007"> <to>tove</to> <from>jani</from> </note> ဒ ဟ က မ မ န ပ တ ယ Entity References တစ ခ ႕အက ၡရ တ မ တ ႔XMLမ သ တ ႔အခ ထ ခ တ ႔အဓ ပ ယ တ ရ ၾက ပ တ ယ less than < character က XML element တစ ခ ရ ႕အတ င မ ထ တ ႔အခ error ဖစ မ ဖစ ပ တ ယ XML parser က ဒ အကၡရ က element တစ ခ ရ ႕ အစပ လ ႔ဘ သ ပန တ ႔အတ က ဖစ ပ တယ အ က ပ စ ၾက င က error ပမ ဖစ ပ တ ယ <message>if salary < 1000 then</message> ဒ error က မ ပၚ အ င < character က entity reference တ စ ခ န ႔အစ ထ ရပ မယ <message>if salary < 1000 then</message> XML မ ၾက တ င သတ မ တ ပ သ entity references င ခ ရ ပ တ ယ တက ယ တ မ မ တ ႔ < န ႔ & တ ႔က သ XML မ illegal ဖစ တ ပ.. greater than character က တ ႔သ င ပ တယ ဒ ပမယ ႔အ က င ဆ က တ ႔entity reference န ႔အစ ထ သ တ ပ ပ 101 Youth Dreams 101

102 Comments in XML XML မ comment ရ တ ႔syntax က တ ႔HTML မ န ႔တ ပ တယ <! This is a comment -- > What is an XML Element? XML document တ စ ခ မ XML elements တ ပ ၀င ပ တ ယ XML element ဆ တ element ရ ႕start tag က နelement ရ ႕ end tag အထ က ဆ လ ပ တယ element တစ ခ မ တ ခ elements တ ထ ပ ပ င ပ တ ယ ရ ရ စ တ လည ပ ပ င ပ တယ element တ မ သ တ ႔ရ ႕attributes တ လ ည ပ ၀င င ပ တယ <bookstore> <book category="children"> <title>harry Potter</title> <author>j K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title>learning XML</title> <author>erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> ဒ ဥပမ မ ဆ <bookstore> န ႔<book> တ ႔မ element contents တ ဖစ ၾကပ တယ သ တ ႔မ တ ခ elements တ ထပ မ ပ ၀င နပ တ ယ <author> က တ ႔text content ပ သ ႔မ text တ ပပ တ ယ ဒ ဥပမ မ <book> မ attribute တစ ခ ရ ပ တ ယ (category= CHILDREN ) XML Naming Rules XML အ နန ႔ အ က ပ အမည ပ ဥပ ဒ တ က လ က န ရပ မယ န မည တ မ letter, numbers တ န ႔တ ခ character တ ပ ၀င င ပ တ ယ န မည တ ဟ န ပ တ ဒ မ မဟ တ punctuation charcter တ စ ခ န ႔မစ င ပ ဘ န မည တ ဟ xml, XML, Xml စတ ႔စက လ တ န ႔မစ င ပ ဘ န မည တ မ spaces တ မပ ၀င င ပ ဘ အ ဒ အ ပင တ ႔ဘ ယ န မည က မဆ အသ ပ င ပ တ ယ ၾက တ င ဖယ ရ ထ တ ႔စက လ မရ ပ ဘ XML Elements are Extensible XML elements တ က အခ က အလ က တ မ မ ပ သယ ဆ င င ဖ ႔အတ က ခ ႔ထ င ရ င ပ တ ယ အ က ပ ဥပမ က ၾက ည ပ 102 Youth Dreams 102

103 <note> <to>tove</to> <from>jani</from> <body>don't forget me this weekend!</body> </note> က န တ ႔အ နန ႔လ ခ င တ ႔ အ က က Output က XML document ရ ႕<to>, <from> န ႔<body> elements တ က န ရယ မယ ႔application တစ ခ က ဖန တ တယ လ ႔ယ ဆၾကပ စ ႔.. MESSAGE To: From: Jani Tove Don't forget me this weekend! အ ဒ အခ မ န က ထ ပ အ ခ က အလ က အပ တ က က န တ ႔အခ လ ထပ ထ ည မယ လ ႔ယ ဆမယ ဆ ရင <note> <date> </date> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> ဒ application က crash ဖစ သ မယ break ဖစ သ င ပ သလ အ ဖက တ ႔No ပ ဒ application အ နန ႔<to>, <from> <body> စတ ႔element တ က ရ တ ႔ ပ တ ႔တ ည တ ႔ output က ထ တ ပ င မ ပ ဖစ ပ တ ယ XML ရ ႕ က င ခ က တစ ခ က တ ႔သ က application က ဖ က ပစ ခင မရ ဘ န ႔ extend ထပ လ ပ င တ ဖစ ပ တ ယ XML Attributes XML elements တ မ HTML လ မ ပ သ ႔ရ ႕start tag အတ င မ attribute တ ရ င ပ တယ Attribute တ က element န ႔ပတ သတ တ ႔အခ က အလ က တ က ထ ပ ပ ပ ႔ပ ပ ပ တ ယ HTML မ တ န က က န တ ႔အ နန ႔<img src= computer.gif > ဆ တ မ က မ တ မ ၾကမ ပ src ဆ တ ႔attribute က <img> element အတ က အခ က အလက တ က ထပ ပ ပ ႔ပ ပ ထ တ ပ ဥပမ <img src="computer.gif"> <a href="demo.asp"> XML attribute တ က Quote အတ င မ ရ ရပ တ ယ single quote ရ double quote ရ ၾက က တ သ င ပ တယ လ တစ ယ က ရ ႕sex အမ အစ က ဖ ပဖ ႔အတ က person ဆ တ ႔tag က ဒ လ ရ သ င ပ တယ 103 Youth Dreams 103

104 <person sex="female"> ဒ မ မဟ တ <person sex='female'> attribute မ အစက တ ည က double quote ပ နတ ႔ဟ မ ဆ အ က က ဥပမ လ မ single quote က အသ ပ င ပ တယ <gangster name='george "Shotgun" Ziegler'> ဒ လ ရ င ပ တ ယ ဒ မ မဟ တ character entity က သ င ပ တယ <gangster name="george "Shotgun" Ziegler"> XML Elements vs. Attributes အ က ပ ဥပမ စ ခ က ယ ဥ ၾကည ပ <person sex="female"> <firstname>anna</firstname> <lastname>smith</lastname> </person> <person> <sex>female</sex> <firstname>anna</firstname> <lastname>smith</lastname> </person> ပထမတစ ခ မ sex က attribute ဖစ ပ တယ န က တစ ခ မ တ ႔sex က element ဖစ ပ တယ ဥပမ စ ခ စလ က တ ည တ ႔အခ က အလက တ က ဖ ပ ပ ပ တ ယ ဘယ အခ န မ attribute က သ ပ ဘ ယ အ ခ န မ element က သ ရမယ ဆ တ ႔ဥပ ဒမရ ပ ဘ HTML မ တ ႔attribute တ က အသ မ ပ တယ XML မ တ ႔အ ဒ တ မသ တ ပ က င ပ တ ယ element က သ attribute အစ ပ သ သင ပ တယ My Favorite Way အ က ဖ ပပ XML documents သ ခ က တ ည တ ႔အခ က အလက တ ပ ၀င ပ တ ယ ပထ မဥပမ မ date attribute က အသ ပ ထ ပ တယ <note date="10/01/2008"> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> အ က ကဒ တ ယ ဥပမ မ တ ႔date element က သ ပ တ ယ <note> <date>10/01/2008</date> 104 Youth Dreams 104

105 <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> date element က မ ထ ပ ပ ခ ႔ထ င ထ တ ႔ပ စ က ဒ တ တ ယ မ က မ တ ႔ရပ မယ ဒ က န အၾက က ဆ ပ စ ပ <note> <date> <day>10</day> <month>01</month> <year>2008</year> </date> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> XML Attributes for Metadata တခ တ ရ မ elements တ က ID references တ ထ ပ ရပ တယ messages> <note id="501"> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> <note id="502"> <to>jani</to> <from>tove</from> <heading>re: Reminder</heading> <body>i will not</body> </note> </messages> ဒ ဥပမ မ ပ တ ႔identifier က တ ႔မတ ည တ ႔notes တ က ခ ခ ပ ဖ ႔ပ ဖစ ပ တ ယ note ရ ႕အစ တ အပ င တ စ ခ မဟ တ ပ ဘ metadata တ က attributes အ နန ႔ သ မ သ င ပ တယ data တ က တ ႔ elements တ အ ဖစ သ မ သ င ပ တ ယ XML Validation မ န က န တ ႔syntax တ န ႔ ရ ထ မ ႔xml document တ စ ခ က well formed လ ႔ ခၚတ င ပ တယ သ ႔ရ ႕syntax rule တ က တ ႔အ ရ ႕မ လည ပ လ ခ ႔ပ ပ -XML document တ မ root element တစ ခ ရ ရမယ -XML tags တ သည case sensitive ဖစ သည 105 Youth Dreams 105

106 -XML elements တ က စနစ တက nested လ ပ ရမယ -XML attribute တန ဖ တ က quote ထ မ ထ ည ရ ရမယ <?xml version="1.0" encoding="iso " <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> Valid XML Documents valid ဖစ တ ႔XML document တ စ ခ ဟ document type definitation (DND) ဥပ ဒက လ က န တ ႔well form xml documents က ဆ လ ပ တ ယ <?xml version="1.0" encoding="iso " <!DOCTYPE note SYSTEM "Note.dtd"> <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> အထက ပ ဥပမ မ ပ တ ႔DOCTYPE ၾက င ခ က က ပင ပ DTD file တစ ခ က မ ငမ ထ တ ဖစ ပ တ ယ အ က မ အ ဒ DTD file ထ က content တ က ဖ ပထ ပ တယ XML DTD DTD ရ ရည ရ ယ ခ က က တ ႔XML document တ စ ခ ရ ႕ဖ ႔စည တ ည ဆ က ပ က define လ ပ ပ ဖ ႔ပ ဖစ ပ တ ယ legal elements တ န ႔structure က သတ မ တ ပ ပ တ ယ <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> XML Schema W3C က DTD အစ သ င တ ႔XML Schema ဆ တ က လည support လ ပ ပ သ တယ <xs:element name="note"> <xs:complextype> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> 106 Youth Dreams 106

107 <xs:element name="body" </xs:sequence> </xs:complextype> type="xs:string"/> </xs:element XML Validator XML document ထ မ error တ ရ တယ ဆ ရင XML application က ရပ လ က မ ဖစ ပ တယ error တ စ ခ က တ ႔တ န ႔ XML document တ စ ခ က processing လ ပ နရက န အ ဒ Program က ရပ လ က မယ လ ႔W3C XML specification က ဖ ပပ တ ယ အ ၾက င ပခ က က တ ႔ XML software က သ ငယ ရမယ မန ရမယ compatible ဖစ ရမယ ဆ တ ႔အတ က ပ HTML မ တ ႔browsers တ ဟ error တ ပ တ ႔document တ က လည ပသ ၾက ပ လ မ ႔မယ XML မ တ ႔error တ က ခ င မ ပ ပ ဘ က န တ ႔XML တ ရ ႕syntax က စစ ဆ င ဖ ႔အတ က XML validator တ စ ခ က ဖန တ အသ ပ င ပ တယ ခင ဗ Viewing XML Files Raw XML file တ က ဘယ browser တ မ မဆ ၾကည င ပ တယ HTML page တ လ မ XML files တ က ပသ မ တ ႔မဟ တ ပ ဘ <?xml version="1.0" encoding="iso " - <note> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>don't forget me this weekend!</body> </note> Displaying XML with CSS XML document တ စ ခက CSS သ ပ ပ စ ခ ဖ ႔ ဖစ င ပ တ ယ အ က ပ ဥပမ မ ပထ ပ တယ CD Catalog XML file က ဒ လ ပ စ ရ ပ မယ <?xml version="1.0" encoding="iso " <?xml-stylesheet type="text/css" href="cd_catalog.css" <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> 107 Youth Dreams 107

108 <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</title> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD>.... </CATALOG> CSS file က ဒ လ ရ ပ မယ CATALOG background-color: #ffffff; width: 100%; CD display: block; margin-bottom: 30pt; margin-left: 0; TITLE color: #FF0000; font-size: 20pt; ARTIST color: #0000FF; font-size: 20pt; COUNTRY,PRICE,YEAR,COMPANY display: block; color: #000000; margin-left: 20pt; အ ဒ ဆ ရင CSS န ႔format လ ပ ထ တ ႔CD catalog က အ က ပ ပ စ မ ဖစ ပ တ ယ 108 Youth Dreams 108

109 XML က CSS န ႔format လ ပ တ က အရ ရ င ဆ နည လမ ပ W3C က တ ႔XSLT က သ တ က recommend လ ပ ပ တ ယ ရ ႕မ ဆက ၾက ည ၾကရ အ င Displaying XML with XSLT XLST က သ ပ တ ႔XML document တစ ခ က HTML အ ဖစ က အသ င ပ င ပ င ပ တ ယ XSLT က XML ရ ႕recommend ပ ခ ရတ ႔style sheet language ဖစ ပ တယ XSLT(eXtensible Stylessheet Language Transformations) က CSS ထက ပ ပ တ ႔ဆ န ပ ရ ပ ထ ပ တ ယ XSLT က အသ ပ ပ က တ ႔ အ က က ဥပမ မ ပသ လ browser နမ ပခင XML က HTML အ ဖစ ပ င တ ဖစ ပ တ ယ ဒ က XML file ပ <!-- Edited by XMLSpy --> <breakfast_menu> <food> <name>belgian Waffles</name> <price>$5.95</price> <description> two of our famous Belgian Waffles with plenty of real maple syrup </description> <calories>650</calories> </food> <food> <name>strawberry Belgian Waffles</name> 109 Youth Dreams 109

110 <price>$7.95</price> <description> light Belgian waffles covered with strawberries and whipped cream </description> <calories>900</calories> </food> <food> <name>berry-berry Belgian Waffles</name> <price>$8.95</price> <description> light Belgian waffles covered with an assortment of fresh berries and whipped cream </description> <calories>900</calories> </food> <food> <name>french Toast</name> <price>$4.50</price> <description> thick slices made from our homemade sourdough bread </description> <calories>600</calories> </food> <food> <name>homestyle Breakfast</name> <price>$6.95</price> <description> two eggs, bacon or sausage, toast, and our ever-popular hash browns 110 Youth Dreams 110

111 </description> <calories>950</calories> </food> </breakfast_menu> XSLT Style Sheet က အ က ပ အတ င ပ ဒ စ ခ ပ င ထ တ ႔result က တ ႔ ဖစ ပ တ ယ ခင ဗ XML file ရ ႕အ ပၚဆ မ ဒ လ စ ၾက င ပ ပ မယ <?xml version="1.0" encoding="iso " <?xml-stylesheet type="text/xsl" href="simple.xsl" ဒ တ ယအ ၾက င က တ ႔XML file က XSLT file န ႔ခ တ ဆတ ပ တ ဖစ ပ တယ အခ အခ န ထ က န တ ႔XML ရ ႕အ ခခ တ က လ႔လ ခ ႔ ပ ဖစ ပ တယ အ ခ က စ ပ PHP န ႔XML န ႔အပ င က ဆက လက လ႔လ ပ မယ PHP XML Expat Parser PHP ရ ႕Built in Expat parser က PHP က သ ပ XML document တ က pricess လ ပ ဖ ႔ ဖစ င စပ တယ What is Expat? XML document တ စ ခ က ဖတ ဖ ႔အသစ ပ ပင ဖ ႔ဖန တ ပ တ က ခ က ထ တ ဖ ႔အတ က XML parser တစ ခ က လ အပ ပ တ ယ XML parsers အ ခခ အ ဖင စ မ ရ ပ တယ 111 Youth Dreams 111

ၿမန မ ႔ အ က င ဆ လ ငယ နည ပည ရ င ၁၀၀ က ဒ တ ယ အၾက မ ၿမ က HACKATHON ၿပ င ပ အတ က စ ရ

ၿမန မ ႔ အ က င ဆ လ ငယ နည ပည ရ င ၁၀၀ က ဒ တ ယ အၾက မ ၿမ က HACKATHON ၿပ င ပ အတ က စ ရ ၿမန မ ႔ အ က င ဆ လ ငယ နည ပည ရ င ၁၀၀ က ဒ တ ယ အၾက မ ၿမ က HACKATHON ၿပ င ပ အတ က စ ရ စ ပ ရ လ ပ ငန မ အတ က နည ပည အ ၿဖင ႔ အ ၿဖရ ၾကရန ၿပ င ပ ၀င မ ၄၈ န ရ ၾက ယ ဥ ၿပ င ၾကမည ၂၀၁၄ စက တင ဘ လ ၅ ရက ( သ ၾက န႔) Ooredoo ၿမန

More information

1. Name in Full (Fill in Blocks) / _ / _ (First Name) (Middle Name) (Last Name)

1. Name in Full (Fill in Blocks) / _ / _ (First Name) (Middle Name) (Last Name) EMBASSY OF THE REPUBLIC OF THE UNION OF MYANMAR, WASHINGTON D.C. APPLICATION FOR ENTRY VISA (SOCIAL) (Social Visa Form for Ex-Myanmar Citizens and Immediate Family only) မန မ င င သ ဖစ ခ ဖ သ မ င ၄င တ ႕

More information

Geometry. Glossary. High School Level. English / Burmese. Translation of Geometry terms based on the Coursework for Geometry Grades 9 to 12.

Geometry. Glossary. High School Level. English / Burmese. Translation of Geometry terms based on the Coursework for Geometry Grades 9 to 12. High School Level Glossary Geometry Glossary English / Burmese Translation of Geometry terms based on the Coursework for Geometry Grades 9 to 12. Word-for-word glossaries are used for testing accommodations

More information

ၿဖည လ က ပ ၿပ ရင ID က Primary Key ပ လ က ရ A င ပ (၂) က ၾကည ပ

ၿဖည လ က ပ ၿပ ရင ID က Primary Key ပ လ က ရ A င ပ (၂) က ၾကည ပ ဒ MySQL က ကၽ န တ န လည သလ သ ရ သလ ရ သ ထ ၿခင ၿဖစ ပ သည မ သ A ၿဖင Aင တ နက ထ မ က က ၿပ ရ ထ ၿခင ၿဖစ ပ သည ကၽ န တ သ သ လ က ရ ထ ၿခင ၿဇစ သၿဖင လ Aပ သည မ ရ ပ က မ ယ င သည မ ရ ပ က န လည ပ စလ ပ သည MySQL ပထမဆ MySQL Run နည

More information

PHP with data handling

PHP with data handling 171 Lesson 18 PHP with data handling Aim Objectives : To provide an introduction data handling with PHP : To give an idea about, What type of data you need to handle? How PHP handle the form data? 18.1

More information

လ လ လ လ လ Computer (User) လ. Computer လ Hardware Software ၂ ၂ Computer လ ( ) Hardware Computer လ Hardware Monitor Keyboard Mouse

လ လ လ လ လ Computer (User) လ. Computer လ Hardware Software ၂ ၂ Computer လ ( ) Hardware Computer လ Hardware Monitor Keyboard Mouse Computer ၂၀၁၆ လ ၇ ၁ Computer လ လ Computer လ လ လ လ လ Computer (User) လ လ လ လ Computer လ Hardware Software ၂ ၂ Computer လ - ( ) Hardware Computer လ Hardware Monitor Keyboard Mouse လ ( ) Software Computer

More information

PHP combined with MySQL are cross platform (means that you can develop in Windows and serve on a Unix platform)

PHP combined with MySQL are cross platform (means that you can develop in Windows and serve on a Unix platform) What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server side scripting language, like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Informix, Oracle, Sybase,

More information

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 7:- PHP Compiled By:- Assistant Professor, SVBIT. Outline Starting to script on server side, Arrays, Function and forms, Advance PHP Databases:-Basic command with PHP examples, Connection to server,

More information

PHP. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

PHP. M hiwa ahamad aziz  Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz) PHP M hiwa ahamad aziz www.raparinweb.com Raparin univercity 1 Server-Side Programming language asp, asp.net, php, jsp, perl, cgi... 2 Of 68 Client-Side Scripting versus Server-Side Scripting Client-side

More information

PHP INTRODUCTION EXAMPLE:

PHP INTRODUCTION EXAMPLE: PHP INTRODUCTION a) AWHAT IS PHP: PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and

More information

You can also set the expiration time of the cookie in another way. It may be easier than using seconds.

You can also set the expiration time of the cookie in another way. It may be easier than using seconds. What is a Cookie? A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will

More information

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

PHP Introduction. Some info on MySQL which we will cover in the next workshop... PHP and MYSQL PHP Introduction PHP is a recursive acronym for PHP: Hypertext Preprocessor -- It is a widely-used open source general-purpose serverside scripting language that is especially suited for

More information

What is PHP? [1] Figure 1 [1]

What is PHP? [1] Figure 1 [1] PHP What is PHP? [1] PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use Figure

More information

Lecture 12. PHP. cp476 PHP

Lecture 12. PHP. cp476 PHP Lecture 12. PHP 1. Origins of PHP 2. Overview of PHP 3. General Syntactic Characteristics 4. Primitives, Operations, and Expressions 5. Control Statements 6. Arrays 7. User-Defined Functions 8. Objects

More information

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL. Hello everyone! Welcome to our PHP + MySQL (Easy to learn) E.T.L. free online course Hope you have installed your XAMPP? And you have created your forms inside the studio file in the htdocs folder using

More information

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users Introduction to PHP Let's Look Back We talked about how to create a form in HTML Forms are one way to interact with users Users can enter information into forms which can be used by you (programmer) We

More information

PHP INTERVIEW QUESTION-ANSWERS

PHP INTERVIEW QUESTION-ANSWERS 1. What is PHP? PHP (recursive acronym for PHP: Hypertext Preprocessor) is the most widely used open source scripting language, majorly used for web-development and application development and can be embedded

More information

php Mr. Amit Patel Hypertext Preprocessor Dept. of I.T.

php Mr. Amit Patel Hypertext Preprocessor Dept. of I.T. php Hypertext Preprocessor Mr. Amit Patel Dept. of I.T..com.com PHP files can contain text, HTML, JavaScript code, and PHP code PHP code are executed on the server, and the result is returned to the browser

More information

Sony Ericsson Bluetooth Connection To Pc Companion Contacts Backup

Sony Ericsson Bluetooth Connection To Pc Companion Contacts Backup Sony Ericsson Bluetooth Connection To Pc Companion Contacts Backup Sony Mobile Communications Update your software using PC Companion Problems connecting to PC Companion and computer using USB cable. Q:

More information

By the end of this section of the practical, the students should be able to:

By the end of this section of the practical, the students should be able to: By the end of this section of the practical, the students should be able to: Display output with PHP built-in and user defined variables, data types and operators Work with text files in PHP Construct

More information

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Introduction: PHP (Hypertext Preprocessor) was invented by Rasmus Lerdorf in 1994. First it was known as Personal Home Page. Later

More information

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP Course Topics IT360: Applied Database Systems Introduction to PHP Database design Relational model SQL Normalization PHP MySQL Database administration Transaction Processing Data Storage and Indexing The

More information

PHP 5 if...else...elseif Statements

PHP 5 if...else...elseif Statements PHP 5 if...else...elseif Statements Conditional statements are used to perform different actions based on different conditions. PHP Conditional Statements Very often when you write code, you want to perform

More information

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP? PHP 5 Introduction What You Should Already Know you should have a basic understanding of the following: HTML CSS What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open

More information

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web Web programming The PHP language Our objective Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web Access data inserted by users into HTML forms Interact

More information

Important Points about PHP:

Important Points about PHP: Important Points about PHP: PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking,

More information

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP Chapter 11 Introduction to PHP 11.1 Origin and Uses of PHP Developed by Rasmus Lerdorf in 1994 PHP is a server-side scripting language, embedded in XHTML pages PHP has good support for form processing

More information

PHP 03. Coding Style Self-processing pages Creating Memory Cookies Writing to a file Including Code Simple String Operations.

PHP 03. Coding Style Self-processing pages Creating Memory Cookies Writing to a file Including Code Simple String Operations. PHP 03 Coding Style Self-processing pages Creating Memory Cookies Writing to a file Including Code Simple String Operations Peter Cho 161B Based on a tutorial by Prof. Daniel Sauter, Rasmus Lerdorf & Kevin

More information

PHP Hypertext Preprocessor

PHP Hypertext Preprocessor PHP Hypertext Preprocessor A brief survey Stefano Fontanelli stefano.fontanelli@sssup.it January 16, 2009 Stefano Fontanelli stefano.fontanelli@sssup.it PHP Hypertext Preprocessor January 16, 2009 1 /

More information

Get in Touch Module 1 - Core PHP XHTML

Get in Touch Module 1 - Core PHP XHTML PHP/MYSQL (Basic + Advanced) Web Technologies Module 1 - Core PHP XHTML What is HTML? Use of HTML. Difference between HTML, XHTML and DHTML. Basic HTML tags. Creating Forms with HTML. Understanding Web

More information

Creating HTML files using Notepad

Creating HTML files using Notepad Reference Materials 3.1 Creating HTML files using Notepad Inside notepad, select the file menu, and then Save As. This will allow you to set the file name, as well as the type of file. Next, select the

More information

Web Engineering (Lecture 08) WAMP

Web Engineering (Lecture 08) WAMP Web Engineering (Lecture 08) WAMP By: Mr. Sadiq Shah Lecturer (CS) Class BS(IT)-6 th semester WAMP WAMP is all-in-one Apache/MySQL/PHP package WAMP stands for: i) Windows ii) iii) iv) Apache MySql PHP

More information

Alpha College of Engineering and Technology. Question Bank

Alpha College of Engineering and Technology. Question Bank Alpha College of Engineering and Technology Department of Information Technology and Computer Engineering Chapter 1 WEB Technology (2160708) Question Bank 1. Give the full name of the following acronyms.

More information

Database Systems Fundamentals

Database Systems Fundamentals Database Systems Fundamentals Using PHP Language Arman Malekzade Amirkabir University of Technology (Tehran Polytechnic) Notice: The class is held under the supervision of Dr.Shiri github.com/arman-malekzade

More information

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP Introduction Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is

More information

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor:

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor: Introduction Server-side Techniques PHP Hypertext Processor A very popular server side language on web Code embedded directly into HTML documents http://hk2.php.net/downloads.php Features Free, open source

More information

Introductory workshop on PHP-MySQL

Introductory workshop on PHP-MySQL Introductory workshop on PHP-MySQL Welcome to Global Certifications and Training from Rocky Sir Download all needed s/w from monster.suven.net Full Stack development : UI + Server Side 1 or more client

More information

Do you need an interpreter for parent/teacher conferences scheduled for?

Do you need an interpreter for parent/teacher conferences scheduled for? عربي ل تحتاج ال متشجم الجتماع ا ل اء االم س المذسس ه المقشس عقذي فى الشجا مه حضشاتكم اعادي زاالىم رج ال المذسس الخاص با الدكما ف اسشع قت ممكه. ف غض ن اساب ع قل ل س ف وشسل ال كم دع ي الى مىزلكم بالم عاد

More information

JavaScript s role on the Web

JavaScript s role on the Web Chris Panayiotou JavaScript s role on the Web JavaScript Programming Language Developed by Netscape for use in Navigator Web Browsers Purpose make web pages (documents) more dynamic and interactive Change

More information

Unit IV- Server Side Technologies (PHP)

Unit IV- Server Side Technologies (PHP) Web Technology Unit IV- Server Side Technologies (PHP) By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and

More information

Open Source Web Application Development - CS310

Open Source Web Application Development - CS310 2018 Open Source Web Application Development - CS310 KASHIF ADEEL bc140401362@vu.edu.pk Introduction PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

More information

PHP 1. Introduction Temasek Polytechnic

PHP 1. Introduction Temasek Polytechnic PHP 1 Introduction Temasek Polytechnic Background Open Source Apache License Free to redistribute with/without source code http://www.apache.org/license.txt Backed by Zend Corporation http://www.zend.com

More information

Course Topics. IT360: Applied Database Systems. Introduction to PHP

Course Topics. IT360: Applied Database Systems. Introduction to PHP IT360: Applied Database Systems Introduction to PHP Chapter 1 and Chapter 6 in "PHP and MySQL Web Development" Course Topics Relational model SQL Database design Normalization PHP MySQL Database administration

More information

PHP Dynamic Web Pages, Without Knowing Beans

PHP Dynamic Web Pages, Without Knowing Beans PHP Dynamic Web Pages, Without Knowing Beans Kimberly Bobrow Jennery Intelliclass kimberly@bobrow.net kimberly@jennery.com Page Agenda Introduction Basic Syntax General Language Constructs File Handling

More information

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser: URLs and web servers 2 1 Server side basics http://server/path/file Usually when you type a URL in your browser: Your computer looks up the server's IP address using DNS Your browser connects to that IP

More information

Web Scripting using PHP

Web Scripting using PHP Web Scripting using PHP Server side scripting No Scripting example - how it works... User on a machine somewhere Server machine So what is a Server Side Scripting Language? Programming language code embedded

More information

Flow Control. Copyleft 2005, Binnur Kurt

Flow Control. Copyleft 2005, Binnur Kurt 10 Flow Control Copyleft 2005, Binnur Kurt Content if, if/else, switch for, while, do/while 513 Conditional Statements Very often when you write code, you want to perform different actions for different

More information

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310 Warm up mini-lab Lab 1 - Functions Type in the following function definition and calls to the function. Test it and understand it. function myprint($str= No String Supplied ) // the argument is optional

More information

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016 DATABASE SYSTEMS Introduction to web programming Database Systems Course, 2016 AGENDA FOR TODAY Client side programming HTML CSS Javascript Server side programming: PHP Installing a local web-server Basic

More information

Web Scripting using PHP

Web Scripting using PHP Web Scripting using PHP Server side scripting So what is a Server Side Scripting Language? Programming language code embedded into a web page PERL PHP PYTHON ASP Different ways of scripting the Web Programming

More information

COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts

COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018 Lecture 7: Dates/Times & Sessions CS 383 Web Development II Wednesday, February 14, 2018 Date/Time When working in PHP, date is primarily tracked as a UNIX timestamp, the number of seconds that have elapsed

More information

Server side basics CS380

Server side basics CS380 1 Server side basics URLs and web servers 2 http://server/path/file Usually when you type a URL in your browser: Your computer looks up the server's IP address using DNS Your browser connects to that IP

More information

PHP can also increase your productivity enormously, both in development time and maintenance time.

PHP can also increase your productivity enormously, both in development time and maintenance time. 4.0 Introduction to stands for Hypertext Processor A recursive definition!. was originally created by Rasmus Lerdorf in 1995. The main implementation of is now produced by The Group and serves as the formal

More information

PHP BASICS BY ALL-TECH SYSTEMS & CO

PHP BASICS BY ALL-TECH SYSTEMS & CO LET S GET STARTED PHP BASICS BY PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. To start with PHP, you must have an idea about the following 1. HTML

More information

PHP by Pearson Education, Inc. All Rights Reserved.

PHP by Pearson Education, Inc. All Rights Reserved. PHP 1992-2012 by Pearson Education, Inc. All Client-side Languages User-agent (web browser) requests a web page JavaScript is executed on PC http request Can affect the Browser and the page itself http

More information

Lab 4: Basic PHP Tutorial, Part 2

Lab 4: Basic PHP Tutorial, Part 2 Lab 4: Basic PHP Tutorial, Part 2 This lab activity provides a continued overview of the basic building blocks of the PHP server-side scripting language. Once again, your task is to thoroughly study the

More information

Instructor s Notes Web Data Management Web Client/Server Concepts. Web Data Management Web Client/Server Concepts

Instructor s Notes Web Data Management Web Client/Server Concepts. Web Data Management Web Client/Server Concepts Instructor s Web Data Management Web Client/Server Concepts Web Data Management 152-155 Web Client/Server Concepts Quick Links & Text References Client / Server Concepts Pages 4 11 Web Data Mgt Software

More information

CMPS 401 Survey of Programming Languages

CMPS 401 Survey of Programming Languages CMPS 401 Survey of Programming Languages Programming Assignment #4 PHP Language On the Ubuntu Operating System Write a PHP program (P4.php) and create a HTML (P4.html) page under the Ubuntu operating system.

More information

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Fasthosts Customer Support An Introduction to PHP Scripting

Fasthosts Customer Support An Introduction to PHP Scripting Fasthosts Customer Support An Introduction to PHP Scripting This guide will introduce some simple yet powerful features of PHP, a popular scripting language, and help you take your first steps towards

More information

Programming for the Web with PHP

Programming for the Web with PHP Aptech Ltd Version 1.0 Page 1 of 11 Table of Contents Aptech Ltd Version 1.0 Page 2 of 11 Abstraction Anonymous Class Apache Arithmetic Operators Array Array Identifier arsort Function Assignment Operators

More information

PHP. MIT 6.470, IAP 2010 Yafim Landa

PHP. MIT 6.470, IAP 2010 Yafim Landa PHP MIT 6.470, IAP 2010 Yafim Landa (landa@mit.edu) LAMP We ll use Linux, Apache, MySQL, and PHP for this course There are alternatives Windows with IIS and ASP Java with Tomcat Other database systems

More information

WEB APPLICATION ENGINEERING II

WEB APPLICATION ENGINEERING II WEB APPLICATION ENGINEERING II Lecture #5 Umar Ibrahim Enesi Objectives Gain understanding of how Cookies and Sessions Work Understand the limitations of Sessions and Cookies Understand how to handle Session

More information

PhpT Point, Simply Easy Learning

PhpT Point, Simply Easy Learning The PHP Hypertext Pre-processor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software

More information

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 (

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 ( Course Title PHP ( Level 1 ( Course Description PHP '' Hypertext Preprocessor" is the most famous server-side programming language in the world. It is used to create a dynamic website and it supports many

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Project One PHP Preview Project One Grading Methodology Return Project One & Evaluation Sheet Project One Evaluation Methodology Consider each project in and of itself

More information

Lecture 7 PHP Basics. Web Engineering CC 552

Lecture 7 PHP Basics. Web Engineering CC 552 Lecture 7 PHP Basics Web Engineering CC 552 Overview n Overview of PHP n Syntactic Characteristics n Primitives n Output n Control statements n Arrays n Functions n WampServer Origins and uses of PHP n

More information

<form>. input elements. </form>

<form>. input elements. </form> CS 183 4/8/2010 A form is an area that can contain form elements. Form elements are elements that allow the user to enter information (like text fields, text area fields, drop-down menus, radio buttons,

More information

PHP Online Training. PHP Online TrainingCourse Duration - 45 Days. Call us: HTML

PHP Online Training. PHP Online TrainingCourse Duration - 45 Days.  Call us: HTML PHP Online Training PHP is a server-side scripting language designed for web development but also used as a generalpurpose programming language. PHP is now installed on more than 244 million websites and

More information

PHP. Interactive Web Systems

PHP. Interactive Web Systems PHP Interactive Web Systems PHP PHP is an open-source server side scripting language. PHP stands for PHP: Hypertext Preprocessor One of the most popular server side languages Second most popular on GitHub

More information

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a LAMP on Linux Working Remotely Introduction to web programming

More information

CPSC 481: CREATIVE INQUIRY TO WSBF

CPSC 481: CREATIVE INQUIRY TO WSBF CPSC 481: CREATIVE INQUIRY TO WSBF J. Yates Monteith, Fall 2013 Schedule HTML and CSS PHP HTML Hypertext Markup Language Markup Language. Does not execute any computation. Marks up text. Decorates it.

More information

(Frequently Asked Questions)

(Frequently Asked Questions) (Frequently Asked Questions) Aptech Ltd. Version 1.0 Page 1 of 9 Table of Contents S# Question 1. How do you create sub domains using PHP? 2. What is the difference between echo and print statements in

More information

B. V. Patel Institute of BMC & IT 2014

B. V. Patel Institute of BMC & IT 2014 Unit 1: Introduction Short Questions: 1. What are the rules for writing PHP code block? 2. Explain comments in your program. What is the purpose of comments in your program. 3. How to declare and use constants

More information

PHP CURRICULUM 6 WEEKS

PHP CURRICULUM 6 WEEKS PHP CURRICULUM 6 WEEKS Hands-On Training In this course, you develop PHP scripts to perform a variety to takes, culminating in the development of a full database-driven Web page. Exercises include: Accessing

More information

DevShala Technologies A-51, Sector 64 Noida, Uttar Pradesh PIN Contact us

DevShala Technologies A-51, Sector 64 Noida, Uttar Pradesh PIN Contact us INTRODUCING PHP The origin of PHP PHP for Web Development & Web Applications PHP History Features of PHP How PHP works with the Web Server What is SERVER & how it works What is ZEND Engine Work of ZEND

More information

Flow Control 10. Flow Control. Content. if Statement. Conditional Statements. if Statement. Example. if, if/else, switch for, while, do/while

Flow Control 10. Flow Control. Content. if Statement. Conditional Statements. if Statement. Example. if, if/else, switch for, while, do/while Content 10 Flow Control if, if/, switch for, while, do/while Copyleft 2005, Binnur Kurt 513 Conditional Statements if Statement Very often when you write code, you want to perform different actions for

More information

CERTIFICATE IN WEB PROGRAMMING

CERTIFICATE IN WEB PROGRAMMING COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING

More information

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology INTERNET PROGRAMMING Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology OUTLINES PHP Basic 2 ARCHITECTURE OF INTERNET database mysql server-side programming

More information

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Princess Nourah bint Abdulrahman University. Computer Sciences Department Princess Nourah bint Abdulrahman University Computer Sciences Department 1 And use http://www.w3schools.com/ PHP Part 3 Objectives Creating a new MySQL Database using Create & Check connection with Database

More information

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script What is Java Script? CMPT 165: Java Script Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University November 7, 2011 JavaScript was designed to add interactivity to HTML pages

More information

Introduction of PHP Created By: Umar Farooque Khan

Introduction of PHP Created By: Umar Farooque Khan 1 Introduction of PHP Created By: Umar Farooque Khan 2 What is PHP? PHP stand for hypertext pre-processor. PHP is a general purpose server side scripting language that is basically used for web development.

More information

Core PHP. PHP output mechanism. Introducing. Language basics. Installing & Configuring PHP. Introducing of PHP keywords. Operators & expressions

Core PHP. PHP output mechanism. Introducing. Language basics. Installing & Configuring PHP. Introducing of PHP keywords. Operators & expressions Core PHP Introducing The origin of PHP PHP for web Development & Web Application PHP History Features of PHP How PHP works with the server What is server & how it works Installing & Configuring PHP PHP

More information

PHP State Maintenance (Cookies, Sessions, Hidden Inputs)

PHP State Maintenance (Cookies, Sessions, Hidden Inputs) PHP State Maintenance (Cookies, Sessions, Hidden Inputs) What is meant by state? The Hypertext Transfer Protocol (HTTP) is stateless. This means that each time a browser requests a page, a connection from

More information

Sample Copy. Not For Distribution

Sample Copy. Not For Distribution PHP Mysql For Advanced Learning i First published in India with the support of EDUCREATION PUBLISHING RZ 94, Sector - 6, Dwarka, New Delhi - 110075 Shubham Vihar, Mangla, Bilaspur, Chhattisgarh - 495001

More information

EMC White Paper. BPS http Listener. Installing and Configuring

EMC White Paper. BPS http Listener. Installing and Configuring EMC White Paper BPS http Listener Installing and Configuring March 2006 Copyright 2005 EMC Corporation. All rights reserved. EMC believes the information in this publication is accurate as of its publication

More information

Web development using PHP & MySQL with HTML5, CSS, JavaScript

Web development using PHP & MySQL with HTML5, CSS, JavaScript Web development using PHP & MySQL with HTML5, CSS, JavaScript Static Webpage Development Introduction to web Browser Website Webpage Content of webpage Static vs dynamic webpage Technologies to create

More information

NETB 329 Lecture 13 Python CGI Programming

NETB 329 Lecture 13 Python CGI Programming NETB 329 Lecture 13 Python CGI Programming 1 of 83 What is CGI? The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom

More information

PHP & My SQL Duration-4-6 Months

PHP & My SQL Duration-4-6 Months PHP & My SQL Duration-4-6 Months Overview of the PHP & My SQL Introduction of different Web Technology Working with the web Client / Server Programs Server Communication Sessions Cookies Typed Languages

More information

COM1004 Web and Internet Technology

COM1004 Web and Internet Technology COM1004 Web and Internet Technology When a user submits a web form, how do we save the information to a database? How do we retrieve that data later? ID NAME EMAIL MESSAGE TIMESTAMP 1 Mike mike@dcs Hi

More information

PHP: The Basics CISC 282. October 18, Approach Thus Far

PHP: The Basics CISC 282. October 18, Approach Thus Far PHP: The Basics CISC 282 October 18, 2017 Approach Thus Far User requests a webpage (.html) Server finds the file(s) and transmits the information Browser receives the information and displays it HTML,

More information

Submitting forms (client-side)

Submitting forms (client-side) Client/Server Submitting forms (client-side) Submitting forms (client-side) Submitting forms (client-side) submit.php $len = strlen($_post["password"]); $name = $_POST["name"]; print "Welcome ". $name;

More information

Figure 1 Forms category in the Insert panel. You set up a form by inserting it and configuring options through the Properties panel.

Figure 1 Forms category in the Insert panel. You set up a form by inserting it and configuring options through the Properties panel. Adobe Dreamweaver CS6 Project 3 guide How to create forms You can use forms to interact with or gather information from site visitors. With forms, visitors can provide feedback, sign a guest book, take

More information

Web Development & SEO (Summer Training Program) 4 Weeks/30 Days

Web Development & SEO (Summer Training Program) 4 Weeks/30 Days (Summer Training Program) 4 Weeks/30 Days PRESENTED BY RoboSpecies Technologies Pvt. Ltd. Office: D-66, First Floor, Sector- 07, Noida, UP Contact us: Email: stp@robospecies.com Website: www.robospecies.com

More information

Some things to watch out for when using PHP and Javascript when building websites

Some things to watch out for when using PHP and Javascript when building websites Some things to watch out for when using PHP and Javascript when building websites Les Hatton 10 Sep 2003 1 PHP PHP is a C-like language which evolved from Perl scripts originally produced by Rasmus Lerdorf

More information

3. WWW and HTTP. Fig.3.1 Architecture of WWW

3. WWW and HTTP. Fig.3.1 Architecture of WWW 3. WWW and HTTP The World Wide Web (WWW) is a repository of information linked together from points all over the world. The WWW has a unique combination of flexibility, portability, and user-friendly features

More information

Subject Name: Advanced Web Programming Subject Code: (13MCA43) 1. what is PHP? Discuss different control statements

Subject Name: Advanced Web Programming Subject Code: (13MCA43) 1. what is PHP? Discuss different control statements PES Institute of Technology, Bangalore South Campus (Formerly PES School of Engineering) (Hosur Road, 1KM before Electronic City, Bangalore-560 100) Dept of MCA INTERNAL TEST (SCHEME AND SOLUTION) 2 Subject

More information

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Control

More information

CSC 375 Database Management Systems

CSC 375 Database Management Systems CSC 375 Database Management Systems Haidar Harmanani Department of Computer Science and Mathematics Lebanese American University Byblos, 1401 2010 Lebanon 1 Introduction PHP PHP Hypertext Preprocessor

More information