PHP MySQL Connect with OOP




Simple connector using a constructor with in the class, I intend to add to this in later examples.

------------------CODE--------------------------
<?php


  class DbConnect
  {
      function __construct($host,$username,$password)
      {
          $this->connect($host,$username,$password);
      }
     
      function connect ($host,$username,$password)
      {
        $con =mysql_connect($host,$username,$password);
         
        if(!$con)
        {
            die('Could not connect: ' . mysql_error());
         }
      }  

  }
 
$DatabaseConnection = new DbConnect("localhost","root","");

?>


No comments:

Post a Comment