Summary of the second day

1. Classes in php

      Description: The definition of a class in PHP starts with class, followed by the class name, followed by a curly brace.

                The curly braces are the properties or methods of the class.

       Syntax: class class name {structure inside the class}

       Example:

class  $People () {

            public  $pname = "xiaoming";

            function  showself (){

                      echo  "Hello  World";

           }

}

2. Objects in php

     Description: To create an instance of a class, the new keyword must be used

     Syntax: $xiaoming =new classname();

     Example:

class  $People () {

            public  $pname = "xiaoming";

            function  showself (){

                      echo  "Hello  World";

           }

}
 $xiaoming=new People();

print_r( $xiaoming);

3. Attributes and attribute type keywords of classes in php

       Description: Variable members inside a class are called properties.

       Syntax: Start with the keyword public protected or private, and then combine it with an ordinary variable.

       public: a type member that is defined as public and can be accessed anywhere

       protect: is defined as a protected class member that can be accessed by itself and its subclasses and superclasses

       private: class members defined as private can only be accessed by the class in which they are defined

       Example:

       class $peo{

             public  $pname=“xiaoming”;

             private function  prun(){

                   echo "run fast";

             }

}

4. Class constants and static variables in php

        Description: Class constants are declared with the keyword const, and static variables are declared with the keyword static

   class class name {

                        const class constant (without $) = simple value;

                        static static variable name (starting with $) = simple value;

}

          Class constants declared by const are not allowed to change.

          Static variables declared by static are executed only once when the class is declared, but can be modified.

          Both are called by ::call.

          When these two are called, they can be called directly with the class name without instantiation.

Fifth, the constructor of the class in php

      A constructor is a function that a class executes automatically when an object is instantiated to help a class to construct an object

6. Inheritance of classes in php

       Sometimes called class extension, it means that the subclass will inherit all the public and protected property methods of the superclass

       In php, the extends keyword is used to achieve inheritance.

       Example:

class  Father{

       public $house="big house";

       private function money(){

                   echo "some money";

     }

}

class  Son extends  Father{

}

$xiaoming = new Son;

echo $xiaoming->house;

$xiaoming->money(); will report an error. because of inaccessibility

Seven, database knowledge

      Introduction: It is an open source relational database management system.

      Main function: Add, delete, modify and check

      PHP connection database and basic operation configuration:

               1. Establish a connection

$con=mysqli_connect("Domain Name","Account","Password","Library Name");

       2. Determine whether to connect

       3. Set the encoding

mysqli_query($con,"set names utf8");

mysqli_query($con,"set charactor_set_client=utf8");

mysqli_query($con,"set charactor_set_result=utf8");

       4. Create sql statement

$sql="select * from 表名 where 1";

       5. Execute the sql statement and get the result

$result=$con->query($sql);

       6. Judging the number of results

if($result->num_rows>0){

     $ jsonInfo = [];

     for($i=0;$rows=$result->fetch_assoc();$i++){

   }

}

       7. Piece together the results

$jsonInfo[$i]=$row;

       8.json return

print_r($jsonInfo);

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325934699&siteId=291194637