Posts

Ajax Introduction Tutorial in PHP

Image
  <?php $servername = "localhost" ; $username = "root" ; $password = "" ; $dbname = "test" ; // Create Connection $conn = new mysqli ( $servername , $username , $password , $dbname ); // Check Connection if ( $conn -> connect_error ) {     die ( "Connection Failed : " . $conn -> connect_error ); } Above File is mysqli_conn.php File Below File is show-data.php File <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0, shrink-to-fit=no" >     < meta http-equiv = "X-UA-Compatible" content = "ie=edge" >     < title > Show Data </ title > </ head > < body >     < table id = "main" border = "0" cellspacing = "0" >         < tr >             < td id =...

Read both tables records by INNER JOIN in php

Image
  <?php $servername = "localhost" ; $username = "root" ; $password = "" ; $database = "studenttwo" ; // Create Connection $conn = new mysqli ( $servername , $username , $password , $database ); // Check Connection if ( $conn -> connect_error ) {     die ( "Connection failed : " . $conn -> connect_error ); } Above File is mysqli_conn.php File. Below File is read.php File. <! DOCTYPE html > < html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport" content = "width=device-width, initial-scale=1.0, shrink-to-fit=no" >     < meta http-equiv = "X-UA-Compatible" content = "ie=edge" >     < title > PHP Table </ title > </ head > < body >     < table border = "1px solid black" cellpadding = "5px" cellspacing = "2px" >         < tr...

Type Hinting in PHP OOPS

Image
  <?php //Type Hinting //Example 1 // function test(array $arr) // { //     echo "<table>"; //     foreach($arr as $k => $v) //     { //         echo "<tr><td>$k</td><td>$v</td></tr>"; //     } //     echo "</table>"; // } // $array = "hkhhlhlh"; // test($array); //Example 2 interface test {     public function doSomething (); } class ABC implements test {     public function doSomething ()     {         echo "Doing Something from ABC Class" ;     } } class XYZ implements test {     public function doSomething ()     {         echo "Doing Something from XYZ Class" ;     }     public function doSomethingElse ()     {         echo "Doing Something Else" ;     } } function test ( ABC $a...

namespaces in PHP OOPS

Image
  <?php // NOTE: Namespace declaration statement has to be the very first statement or after any declare call in the script // No code may exist outside of namespace {} namespace abc {     class xyz {} } namespace def {     class xyz     {         public function __construct ()         {             echo "XYZ from DEF namespace" ;         }     } } //If there is no Name present for namespace then it will consider as "Global namespace" as shown below: namespace {     class xyz     {         public function __construct ()         {             echo "XYZ from Global namespace" ;         }     }     $obj = new xyz ();     echo "<br><br>" ;     $objTwo = new def\ xyz ();  ...

Access Levels in Traits in PHP

Image
  <?php trait abc {     private function xyz ()     {         echo "XYZ method from trait abc" ;     } } class test {     use abc {         abc ::xyz as public;     //Changing the Access Modifier from private to public of Method xyz()         abc ::xyz as public abcXYZ;   //Changing the Access Modifier from private to public of method xyz()         // as well as Changing the name of method xyz() to abcXYZ()     } } $obj = new test (); $obj -> xyz (); echo "<br><br>" ; $obj -> abcXYZ ();

Handling Conflicts in Traits in PHP

Image
  <?php //When multiple trait have same named method then we can call both methods as shown below : trait one {     public function test ()     {         echo "TEST method from one trait." ;     } } trait two {     public function test ()     {         echo "TEST method from two trait." ;     } } class abc {     use one , two {         // one::test insteadof two;    //Here test() method in trait one will call         // two::test insteadof one;    //Here test() method in trait two will call         //Here below First of all, trait "two" method will call and then trait "one" method will call         two ::test insteadof one ;         one ::test as OneTest;         //Here below First of all, trait "one" method will call an...

Method Overriding in Traits in PHP

Image
  <?php class Base {     public function abc ()     {         echo "ABC method from Base class." ;     } } //The trait method(Here, abc() Method) will get priority compared to Parent class Method(Here, abc() Method) trait Test {     public function abc ()     {         echo "ABC method from test trait." ;     } } class Child extends Base {     use Test ;     public function abc ()     {         echo "ABC method from Child class." ;     } } $obj = new Child (); $obj -> abc ();