www.emilbak.com



User: Pass:    rss

PHP MySQL Database Connection

Use this function to make a MySQL Database connection:
// Database Connection Variables you will need to change these
var $dbHost="host";
var $dbUser="user";
var $dbPass ="password";
var $dbName= "dbname";
function DB_databaseConnect(){
         // Connect to the mySQL Server and Select the database
        $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
        if (!$dbLink)
            die ("Database Class: Couldn't connect to mySQL Server");
        mysql_select_db($this->dbName, $dbLink)
            or die ("Database Class: Couldn't open Database");
        return $dbLink;        
  }


Below is an example on how you can use the database connection script:
        $query = "SELECT id,title,author,date,body,menuID
                  FR_OM table WHERE menuID='".$_GET['menuID']."'" ;
        $result = $this->DB_executeQuery($query,$this->dbLink) ;
        $row = mysql_fetch_assoc($result) ;
        if(isset($row['id'])){
            $this->articleID = $row['id'] ;
            $this->readArticle() ;
        } else {
            $this->pageNotFound() ;
        }