November 3, 2017

Understand OOP right now: PDO class and method tutor

Basically am new to methods and still improving myself. When it comes to OOP(Object Oriented Programming) most Developer Beginners becomes afraid. Well i see no much thing in it, and it give YOu a 100% opportunity to think and improve yourself. lets take for example

class Skamod{


this is a Class and as well i understand it. OOP give you an excellent opportunity to keep your codes aside messing around your script files with much codes. You create a file and store them seperately then call them using the (include_once()) and assign it to a simple variable which.

      class DB{
               //you database Connection goes here and
to call that you only need a simple trick which is this

$skamod = new DB;

You see is very simple and easy to use.

            METHODS ON OOP

Well like i said am new to OOP yeah and would like someone who is also new to ride along like me.
let's take for example

public function Samuel(){
           //this is a good example of a method

The above method works just like class except for the function attached to it... after instantiating my class (which is where your DB connection usually goes) now to use this is very simple

you can now say
" $sam = $skamod->samuel()

which will now refer to the method above.

     class DB{

                you can use the try to instantiate a mysql connction
                return $conn;

class User{
    $db = new DB;
    // you will now call you db with a __construct method();
     public function __construct($db){
        $this->db = $db
// asging it to a simple variable for you to recal quickly
   public funciton sam(){
       //your codes goes here


Now to call sam is very simple

  $exec = new User;


No comments:

Post a Comment