PHP: Getting Started

(အခုေရးမယ့္ က်ူတိုရီရယ္ေတြက PHP စလံုးေရးစ သမားေတြအတြက္ ျဖစ္ပါတယ္။ PHP ကို နည္းနည္း တီးမိေခါက္မိ ရွိသူမ်ားအတြက္လဲ Practical Real-World application (GuestBook, User Registration, User Authentication, etc) ေတြလည္း အလ်င္းသင့္သလို တင္ေပးပါမည္။)

What is PHP?

PHP ရဲ႕ official site ျဖစ္တဲ့ PHP.net ကစာသားကို ယူေျပာရရင္

“PHP is an HTML-embedded scripting language.”

PHP ဆိုတာ HTML page ေတြထဲမွာ တပါထဲ ျမဳပ္ေရးႏိုင္တဲ့ scripting language တစ္ခုပါတဲ့။ သူ႔ရဲ႕ ေရးသားတဲ့ပံုစံ (syntax) ေတြဟာ C, Java, Perl စတဲ့ language ေတြကို အတုခိုးထားေပမယ့္… သူ႔ရဲ႕ ကိုယ္ပိုင္ feature ေတြလဲ အမ်ားႀကီးရွိပါတယ္.. PHP ရဲ႕ ရည္ရြယ္ခ်က္ကေတာ့ Web Developer ေတြ Dynamic Site ေတြေရးတဲ့အခါမွာ လြယ္လြယ္ကူကူ ျမန္ျမန္ဆန္ဆန္ေရးႏိုင္ဖို႔ျဖစ္ပါတယ္.. PHP ကို အစကေတာ့ Personal Home Page လို႔ေခၚေပမယ့္.. အခုအခါမွာေတာ့ PHP: Hypertext Preprocessor လို႔ေခၚပါတယ္.. ဘာလို႔လဲဆိုေတာ့ PHP Script ေတြက HTML Page အျဖစ္မေျပာင္းခင္မွာ Data ေတြကို ႀကိဳတင္ပီး တြက္ခ်က္ (Preprocess) ေပးရလို႔ ျဖစ္ပါတယ္..

PHP ဘယ္လို အလုပ္လုပ္ေပးသလဲဆိုေတာ့.. တစ္ေယာက္ေယာက္က site ကို ၾကည့္တဲ့အခါ… Web server က PHP code ေတြကို process လုပ္ပါတယ္.. အဲအခါမွာ.. ဘယ္အပိုင္းေတြကို Visitor ေတြကို ျပရမယ္ (ဥပမာ -  စာသားေတြ၊ ပံုေတြ) တျခားလုပ္ေဆာင္ခ်က္ေတြကိုေတာ့ မျပဖူး (ဥပမာ – ဖိုင္ေရးတာ ဖတ္တာေတြ၊ သခၤ်ာတြက္ခ်က္မႈေတြ၊ Database နဲ႔ခ်ိတ္ဆက္တာေတြ) ဆိုတာေတြ ခြဲျခားပါတယ္.. အဲဒါအပီးမွာေတာ့ PHP code ေတြကို Plain HTML အျဖစ္ ဘာသာျပန္လိုက္ပီး၊ Visitor ရဲ႕ Web Browser ဆီကို ျပန္ပို႔ေပးလိုက္ပါတယ္…

How PHP Works

How PHP Works

Necessary Setup

PHP ဟာ Server-sided Scripting Language ျဖစ္တာေၾကာင့္ Web Server လိုပါမယ္။ အခ်က္အလက္ေတြ သိမ္းဖို႔၊ ျပန္ထုတ္ျပဖို႔ Database software တစ္ခုလိုပါမယ္။ အဓိကေတာ့ PHP code ေတြကို ဘာသာျပန္ေပးမယ့္ PHP Interpreter လိုပါမယ္။

PHP အတြက္ အေကာင္းဆံုး Web Server ကေတာ့ Apache Web Server ျဖစ္ပါတယ္။ Database System ကေတာ့ MySQL ပါ။

PHP Interpreter, Apache Web Server နဲ႔ MySQL ကို တစ္ခုခ်င္းစီသြင္းလို႔ရေပမယ့္ configuration လုပ္တဲ့အခါမွာ အခက္အခဲရွိႏိုင္ပါတယ္။ အခုက Basic Level ျဖစ္တဲ့အတြက္ အားလံုး တစ္ပါထဲပါပီး configure လုပ္ပီးသားျဖစ္တဲ့ XAMPP or WAMP နဲ႔ပဲ သံုးပါမယ္။ XAMPP ရဲ႕ အေၾကာင္းကို Ahkeno ရဲ႕ About XAMPP မွာဖတ္ႏိုင္ပါတယ္။ XAMPP သြင္းနည္းကိုေတာ့ ကိုသီဟရဲ႕ How to Install XAMPP မွာ ဖတ္ႏိုင္ပါတယ္။

Web Server, Database System, PHP Interpreter စတာေတြ သြင္းပီးသြားရင္ PHP ေရးဖို႔အတြက္ Editor လိုပါဦးမယ္။ Powerful ျဖစ္တဲ့ PHP IDE ေတြရွိေပမယ့္ အေျခခံအဆင့္မွာေတာ့ ႐ိုး႐ိုး Text Editor နဲ႔ပဲေရးျပသြားပါမယ္။ PHP ကို Windows မွာ ပါၿပီးသားျဖစ္တဲ့ Notepad နဲ႔ေရးလို႔ရေပမယ့္ Line Number, Syntax Highlighting ေတြပါတဲ့ Notepad++ ကို သံုးပါမယ္။

Your First PHP-enabled Page

PHP code ေတြကို HTML code ေတြထဲမွာ ေရာေရးလို႔ရပါတယ္။ PHP code မွန္းသိေစဖို႔ <?php (open tag) နဲ႔ ?> (close tag) ၾကားထဲမွာ PHP code ေတြထည့္ေရးရပါတယ္။ ကဲကၽြန္ေတာ္တို႔ရဲ႕ ပထမဆံုး PHP page တစ္ခု ေရးၾကည့္ၾကမယ္။

XAMPP ကို Default အတိုင္း သြင္းခဲ့မယ္ဆိုရင္ C:\xampp\htdocs ထဲမွာ php ဆိုတဲ့ Folder တစ္ခုေဆာက္လိုက္ပါ။

Notepad++ ဖြင့္ပီး ေအာက္ပါ code ေတြ ႐ိုက္ထည့္ၿပီး C:\xampp\htdocs\php ထဲမွာ firstpage.php လို႔ သိမ္းေပးပါ။

<html>
<head>
<title>My First PHP-enabled Page</title>
<body>
<?php
echo "This is my first PHP-enabled page!";
?>
</body>
</html>

Firefox (သို႔) Web Browser တစ္ခုခုကို ဖြင့္ပီး http://localhost/php/firstpage.php လို႔ Address Bar မွာ ႐ိုက္ထည့္ပီး ေခၚၾကည့္ပါ။ ေအာက္ပါပံုေပၚလာရင္ ကၽြန္ေတာ္တို႔ ပထမဆံုး PHP page ကို ေအာင္ျမင္စြာ ဖန္တီးႏိုင္ၿပီျဖစ္ပါတယ္။

First PHP Page

First PHP Page

Facebook comments:

4 Responses

  1. caspertyzin says:

    PHP ကို အခုမှ စလေ့လာနေတာပါ … လမ်းညွှန်မှုတွေအတွက် ကျေးဇူးအများကြီးတင်ပါတယ်…

  2. Yaungsin says:

    hi, I couldn’t read this post. how can I do? pls kindly reply me. Thanks.

  3. Yaungsin says:

    May I know which font type did you used for this post? because I can’t read the posts such as PHP: Getting Started, PHP: Syntax and PHP: Variables. I can read all other posts. any idea? Thank you.

  4. Thu Zar says:

    @Yaungsin
    I also can’t read this post.but I copy this post at notepad.
    Notepad can use zawgyiOne.I think you can read the posts such as PHP: Getting Started, PHP: Syntax and PHP: Variables.

Leave a comment


*