Giter VIP home page Giter VIP logo

php_exercise's Introduction

  •   PHP คืออะไร ใช้ทำอะไร ?

     PHP คือ ภาษาเขียนโปรแกรมที่ใช้ทำ website ฝั่ง back-end
    
  •   PHP ใช้ยังไง ?

     ในการเขียนโปรแกรมไม่ว่าจะภาษาไหน จะเขียนได้ต้องมี environment 2 อย่าง คือ
      1. Editor : ที่ใช้เขียน ใช้ Debug ดู error แก้ไข้โค้ด รันดูผลลัพธ์ผ่าน terminal
      2. compiler/runtime ของภาษานั้นๆ
    
           แต่ในบางภาษาอย่าง PHP จะมี tool ที่ช่วยให้การพัฒนาโปรแกรมง่ายขึ้น PHP เป็นภาษาใช้พัฒนาเว็บฝั่ง Server
     ดังนั้น จึงมีโปรแกรมที่เรียกว่า web server จำลอง web server ให้เราทำให้เราเขียนโค้ด รัน แล้วดูผลลัพธ์ได้ว่าหน้าเว็บ
     มันจะเปลี่ยนไปยังไง ตัวอย่างโปรแกรม web server เช่น  xampp , wampServer , LampServer
    
           xampp เป็นโปรแกรมที่ประกอบไปด้วย โปรแกรมย่อย 4 ตัว คือ
      1.  Apache : โปรแกรมจำลอง web server
      2.  MySQL : โปรแกรมฐานข้อมูล
      3.  phpMyAdmin : โปรแกรม/เว็บจัดการฐานข้อมูล MySQL
      4.  PHP : โปรแกรมแปลภาษา PHP 
    
      ดังนั้น ถ้าเราโหลด xampp มาใช้ เราก็ไม่ต้องโหลด PHP เพิ่ม เพราะมันมีมาให้แล้ว เราแค่มี editor ก็เริ่มเขียนโปรแกรม
      ภาษา PHP ได้เลย editor ที่ใช้เขียน และ debug PHP เช่น window - vscode , mac - sublimetext
    
      การรันดูผลลัพธ์โปรแกรมภาษา PHP ทำได้ 2 แบบ ( ขึ้นอยู่กับ syntax ที่เขียนด้วย เช่น <br/> ต้องรันผ่านเว็บ
      แต่ถ้าใช้ "\n" ต้องรันผ่าน terminal ถึงจะเห็นว่ามัน เว้นวรรคให้ )
      1.  รันดูผลลัพธ์ผ่าน terminal ของ editor ที่ใช้ : ให้พิมพ์คำสั่ง  php file_name.php
      2.  รันดูผลลัพธ์บน web server : ทำได้ 2 วิธี
            >>  วิธีแรก :  เปิด xampp รัน Apache กับ MySQL  >> กดรันโค้ด
            >>  วิธีที่สอง : สำหรับคนใช้ vscode สามารถ install extension ชื่อ PHP Server เวลาจะรันดูผลลัพธ์โค้ด PHP
                         ไม่ต้องรัน xampp (แต่ต้องมีนะ) >> right click แล้วเลือก PHP Server
    




1.   PHP BASIC  🧠

  •   input  :  echo "Hello World !
  •   output  :  echo "Hello World !
  •   condition  :  if...elseif...else   switch (case)
  •   loop  :  while   do-while   for ($x = 0; $x <= 10; $x++)   foreach ($colors as $value)   break;   continue;
  •   Array  :  CREATE : $cars = array("Volvo", "BMW", "Toyota"); OR array();   ACCESS : $cars[0]
  •   String  :  strlen()   str_replace()   . . .
  •   File  :  echo readfile("file.txt");   $myfile = fopen("webdictionary.txt", "r"); ต้อง fclose($myfile);ด้วย  
  •   Cookies & Session  :  setcookie(name, value, expire, path, domain, secure, httponly);   session_start();

2.   PHP OOP  🧠

  •   function  :  function helloWorld() {...}

  •   class  :  วิธีเรียกใช้คลาส คือ new class ดังตัวอย่าง $strawberry = new Strawberry("Strawberry", "red");   วิธีใช้ method ในคลาสใช้เครื่องหมาย -> ดังตัวอย่าง $strawberry->message();   วิธีสร้างคลาส และกำหนด condtructor ดังตัวอย่างข้างล่าง

    class Fruit
    {
       public $name;
       function __construct($name)
       {
             $this->name = $name;
       }
    }
    
  •   inheritance  :  class Strawberry extends Fruit {...}


3.   PHP DATABASE  🧠

           มี 2 API/driver ให้ใช้  คือ PDO (ใช้ได้กับ 12 ฐานข้อมูล) กับ MySQLi (ใช้ได้แค่กับฐานข้อมูล MySQL) ก่อนจะใช้ก็ 
  install API/driver ก่อน
  • connect database แบบใช้ PDO

    <?php
        $servername = "localhost";
        $username = "username";
        $password = "password";
    
        try
        {
             $conn = new PDO("mysql:host=$servername", $username, $password);
    
             // set the PDO error mode to exception
             $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             $sql = "CREATE DATABASE myDBPDO";
    
             // use exec() because no results are returned
             $conn->exec($sql);
             echo "Database created successfully<br>";
        }
        catch(PDOException $e)
        {
             echo $sql . "<br>" . $e->getMessage();
        }
        $conn = null;
    ?>
    




  • BEGINNER   :   ฝึกให้คุ้นกับ syntax ฝึก logic

    • w3resource   :   โจทย์ฝึก logic
    • tutorialsclass   :   โจทย์แนวฝึกใช้ syntax
    • techstudy   :   โจทย์แนวฝึกใช้ syntax ให้คล่อง loop , array , ...
    • javatpoint   :   มีอธิบายโค้ด
    • edabit   :   โจทย์คล้ายๆ leetcode เลือกระดับได้ เหมาะใช้ฝึกทำก่อนไปสัมภาษณ์งาน
  • INTERMEDIATE   :   ฝึกทำโปรเจค ฝึกอ่านโค้ด learning by doing PHP project with source code โหลดมาลองรัน ลองแก้ ลองทำความเข้าใจ

    • sourcecodester   :   มีอธิบาย idea และ Techstack ค่อนข้างละเอียด
    • phpgurukul   :   มีอธิบาย idea และ Techstack
    • interviewbit   :   แนะนำโปรเจค php บน github ที่น่าสนใจ
    • hackr.io   :   แนะนำโปรเจค php บน github ที่น่าสนใจ
    • code-projects   :   มีอธิบาย idea และ Techstack ค่อนข้างละเอียด
    • phptpoint   :   มีวิดิโอพาทำ
    • projectworlds   :   มีวิดิโอพาทำ
    • projectsgeek   :   มีอธิบาย idea และ Techstack
    • itsourcecode   :   มีวิดิโอพาทำ

php_exercise's People

Contributors

arisa-kaewsuan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.