PHPBuilder - class for database connection and database selection



RSS Twitter
Snippets Databases

class for database connection and database selection

by: Rameshwor Maharjan
|
June 18, 2006

Version: 1.0

Type: Full Script

Category: Databases

License: GNU General Public License

Description: uses of constructor in class for database connection and selection



<?
class db 
{
 var $link;

  function db($host,$dbUser,$dbPass,$dbName)              //constructor 
  {
   	 $this->link=mysql_connect($host,$dbUser,$dbPass);                //return link identifier if success,or false on failure 
	if($this->link==false)
	{
	  echo("Database connection failed");       
	}
	else
	{
	  if(mysql_select_db($dbName,$this->link)==false)          //return true on sucess,or false on failure
	  {
	    echo("Database not found");
	  }
	}
  }
}

 $obj=new db("localhost","root","","databasename");
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Rameshwor Maharjan

Comment:



Comment:

(Maximum characters: 1200). You have characters left.