I have posted an earlier version of this and here is the improved version from the feedback I recieved. Some of the feedback I received was;Don't chain method (tried my best to limit this)Do not use print() or die() and an error response (still a little lost, but I did attempt to use a redirect to a custom error page)I tried my best to rewrite the code, I am still very new to this so go easy. I did read up on OOP methodology and read about Interfacing and Implementation, so I tried to incorporate that in my class.I would love to see some different ideas on how to make this the most efficient as possible. I am sure it needs a ton of changing, but that is why I am here to help me learn and grow. I am a visual learner so if possible actual code would be awesome, but any response would be greatly appreciated.<?phpclass Mysql{        private $user;        private $pass;        private $data;        private $host;        public function __construct($user,$pass,$data,$host)        {                $this->user = $user;                $this->pass = $pass;                $this->data = $data;                $this->host = $host;                $this->process();        }        /* INTERFACE */        private function process()        {                if($this->verifyNullFields()==true)                {                        if($this->verifyDatabaseConnection()==true)                        {                                if($this->verifyDatabaseExist()==true)                                {                                        print('ALL PASSED'); //for debugging                                }                                else                                {                                        print('redirect to custom error page will go here');                                }                        }                        else                        {                                  print('redirect to custom error page will go here');                        }                }                else                {                        print('redirect to custom error page will go here');                }        }        /* IMPLEMENTATIONS */        private function verifyNullFields()        {                if($this->user != NULL)                {                        if($this->data != NULL)                        {                                if($this->host != NULL)                                {                                        return true;                                }                                else                                {                                        return false;                                }                        }                        else                        {                                return false;                        }                }                else                {                        return false;                }        }        private function verifyDatabaseConnection()        {                $link = @mysql_connect($this->host,$this->user,$this->pass);                if(!$link)                {                        return false ;                }                else                {                        return true;                }        }        private function verifyDatabaseExist()        {                $db = @mysql_select_db($this->data);                if(!$db)                {                        return false;                }                else                {                        return true;                }        }}?><?php$m = new Mysql(root,,magic,localhost);?>
Learning OOP PHP, simple MySQL connection class.
php;php5;object oriented
Let me show my version of this code:DatabaseException.php:class DatabaseException extends Exception {}Database.php:abstract class Database {    protected $login;    protected $password;    protected $database;    protected $hostname;    public function __construct($login, $password, $database, $hostname) {        // NB: password not checked and may be empty        $this->throwExceptionIfNotSet('login', $login);        $this->throwExceptionIfNotSet('database', $database);        $this->throwExceptionIfNotSet('hostname', $hostname);        $this->login    = $login;        $this->password = $password;        $this->database = $database;        $this->hostname = $hostname;    }    private function throwExceptionIfNotSet($argName, $argValue) {        if (empty($argValue)) {            throw new DatabaseException('${argName}' not set);        }    }}Mysql.php:class Mysql extends Database {    private $link = null;    public function __construct($login, $password, $database, $hostname) {        parent::__construct($login, $password, $database, $hostname);        $this->connect();        $this->selectDatabase();    }    public function connect() {        if (! is_null($this->link)) {            return;        }        $link = @mysql_connect($this->hostname, $this->login, $this->password);        if (! $link) {            throw new DatabaseException(                sprintf(                    'Cannot connect to database. mysql_connect() to %s with login %s fails',                    $this->hostname,                    $this->login                )            );        }    }    public function selectDatabase() {        $ret = @mysql_select_db($this->database, $this->link);        if (! $ret) {            throw new DatabaseException(Cannot select database {$this->database});        }    }}application.php:try {    $db = new Mysql('root', '', 'magic', 'localhost');    print('ALL PASSED'); //for debugging} catch (DatabaseException $ex) {    print('redirect to custom error page will go here');}