User and Database classes in PHP I am learning some OOP on PHP and I have developed some sample code to practise. 

Ignoring the functionality, I just want to learn the "best" or "better" way to write OOP codes in PHP. 

The following is my code and I hope anyone who has been doing PHP can help to review or comment for any improvements or weaknesses on my code.

I want to develop my style of code in which copy-and paste is minimum and functionality expandability is rich. For example, the execute() function in the UserDB class is basically the same function and can be used widespread in many diff db class. Do I need to copy and paste the code again or should I just moved this piece of code to abstract class? 

How can I optimized my code to made it better for future functionalities such as other select, insert, update and delete while maintaining readability and still within OOP standards? 

&lt;?php

    require_once "sys_config.php";
    require_once "general.inc";
    $para[":user"]= "%";

    $dataset = UserFactory::getUsers($para);

    var_dump($dataset);

?&gt;


UserFactory class

&lt;?php

    class UserFactory{

        public static function getUsers($para)
        {
            $db = new UserDB("CALL getUsers(:user)",$para); //sp

            $objs = $db-&gt;execute();
            if(!empty($objs))
                foreach( $objs as $obj)
                {
                    $users[] = new user($obj);
                }
            return $users;
        }

    }


?&gt;


UserDB class

&lt;?php

    Class UserDB extends Database{

        protected $conn;
        protected $SQL;
        protected $para;

        function __construct($SQL, $para)
        {
            parent::__construct();

            $this-&gt;conn = parent::getConn();
            $this-&gt;SQL = $SQL;
            $this-&gt;para = $para;
        }

        function execute()
        {

            $query = $this-&gt;conn-&gt;prepare($this-&gt;SQL);
            if(!empty($this-&gt;para))
                foreach($this-&gt;para as $key=&gt;$val)
                {
                    $query-&gt;bindParam($key,$val);
                }
            $results = $query-&gt;execute();

            $dataset = null;

            if($results)
            {
                while($row = $query-&gt;fetch(PDO::FETCH_OBJ))
                {
                    $dataset[]=$row;
                }
            }   

            unset($this-&gt;conn); 

            parent::__destruct();

            return $dataset;

        }

    }

?&gt;


Database abstract class

&lt;?php

    abstract Class Database{

        protected $conn;

        function __construct()
        {
            $this-&gt;conn = new PDO ("mysql:host=".DB_LOCATION.";dbname=".DB_NAME,DB_USER,DB_PASS);

        }

        function __destruct()
        {
            unset($this-&gt;conn);

        }

        function getConn()
        {
            return $this-&gt;conn;
        }

        abstract function execute();
    }

?&gt;


User object class

&lt;?php

    class User{

        private $fullname;
        private $id;

        function __construct($userObj)
        {
            $this-&gt;fullname = $userObj-&gt;fullName;
            $this-&gt;id = $userObj-&gt;id;
        }

        function setFullname($fullname)
        {
            $this-&gt;fullname = $fullname;
        }

        function getFullname()
        {
            return $this-&gt;fullname;
        }

        function setId($id)
        {
            $this-&gt;id = $id;
        }

        function getId()
        {
            return $this-&gt;id;
        }
    }

?&gt;
Just a few comments on the code as it stands so far: 


You're using pretty old-school file dependency management (which isn't the same as dependency management) by explicitly including things.  I'd strongly suggest you look into the SPL autoload system, write an autoloader that can find where your classes are located in the filesystem and rely on the autoloader to handle the file dependency management instead.  It means that only code that's actually going to be used will be included and you won't get into a situation where you have loads of included classes but only a few get used, or where you're not sure what's been included.  
You're using static methods.  Generally, statics are frowned upon because they're not considered to be good OO practice.  Sometimes they're necessary, but as a rule you should avoid them.  Any other class that makes use of the static call becomes tightly coupled to the class that implements it, reducing re-usability and testability (it becomes very difficult to test the dependant modules in isolation because you can't easily replace the static with a mock implementation).  I'd advise refactoring your factory to work in a non-static way. 
Your Database class seems like it might not be necessary.  It's merely a wrapper around PDO, and actually hides most of the PDO class functionality.  I'd suggest you might be better off using PDO directly, as it's got a well-documented interface and you'll have full access to all the PDO functionality in the consuming classes instead of the small subset your Database class provides.  


I would say that on the whole you're on basically the right track though.  It's certainly better than my own early efforts with OOP.  Don't worry, thinking in an "objecty" way is something that comes with practice and experience.