View Single Post
Old 07-03-2008, 08:12 AM   #11 (permalink)
delayedinsanity
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

This part here:

PHP Code:
    public function specs($dbn$user$pass
    {
        
        
$this->dbn $dbn;
        
$this->user $user;
        
$this->pass $pass;
     
$this->dbtestcon $dbtestcon;
     
    
        
$dbtestcon mysql_connect($dbn$user$pass);
    
        if (!
$dbtestcon
        {
            die(
'Could not connect: ' mysql_error());
        }
        echo 
'Connected successfully';
    } 
Should be written:

PHP Code:
    public function specs ($dbn$user$pass
    {
        
        
$this->dbn $dbn;
        
$this->user $user;
        
$this->pass $pass;

        
// You were originally trying to assign an empty variable, $dbtestcon to $this->dbtestcon
        
$this->dbtestcon mysql_connect($dbn$user$pass);

        
// You need to use $this to assign properties to a global reference inside your class
        // Any variables that are called within a function directly (such as $dbtestcon as
        // opposed to $this->dbtestcon) are local to that function and do not exist in the global
        // scope of a class.
        
if ( ! $this->$dbtestcon
        {
            die(
'Could not connect: ' mysql_error());
        }

        echo 
'Connected successfully';
    } 
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-03-2008)