title: How to get database in php using class & function oops concepts
body: <p>I am new developer in php. I'm writing below code a class and functions to connect to the database. but code was not working how to create class and function oops concept help me.</p>
  
  <p><strong>code:</strong></p>
  
  <pre><code>class database {
  
  #code
  var $host = "localhost";
  var $username ="root";
  var $password ="";
  
  var $dbase ="blue";
  var $myconnect;
  
  function connectTodata()
  {
      $conn = mysql_connect($this-&gt;host, $this-&gt;username, $this-&gt;password);
  
      if(!$conn)
      {
          die("Cannot Connect to the datagase");
      }
      else
      {
          $his-&gt;myconnect = $conn;
          echo "Connect Established";
      }
      return $myconnect;
  
  }
   function selectDatabase() // selecting the database.
  {
      mysql_select_db($this-&gt;database);  //use php inbuild functions for select database
  
      if(mysql_error()) // if error occured display the error message
      {
  
          echo "Cannot find the database ".$this-&gt;database;
  
      }
       echo "Database selected..";       
  }
  
  function closeConnection() // close the connection
  {
      mysql_close($this-&gt;myconn);
  
      echo "Connection closed";
     }
  }
  </code></pre>