Skip to main content

Posts

Showing posts from December 18, 2013

database connection through class

<?php class createConnection //create a class for make connection {     var $host="localhost";     var $username="username";    // specify the sever details for mysql     Var $password="password";     var $database="database name";     var $myconn;     function connectToDatabase() // create a function for connect database     {         $conn= mysql_connect($this->host,$this->username,$this->password);         if(!$conn)// testing the connection         {             die ("Cannot connect to the database");         }         else         {             $this->myconn = $conn;             echo "Connection established";         }         return $this->myconn;     }