Part of the EllisLab Network

Bug Report

Allow Port Configuration Setting for MySql

Date: 07/26/2008 Severity: Minor
Status: Resolved Reporter: Randy Casburn
Version: 1.7.0 SVN
Keywords: Libraries, Database Class
Forum Thread: http://codeigniter.com/forums/viewthread/86382/

Description

Currently CI is restricted to using MySQL on the default port 3306.  A simple change to mysql_driver.php will allow the use of $db[‘default’][‘port’] = ‘NUMBER’; configuration parameter to be used to change the MySql server port at run time.

Code sample changes lines 48 - 72 in mysql-driver.php and adds the options port configuration option.

database configuration file requires config:

$db[‘default’][‘port’] = ‘PORTNUM’;

Where PORTNUM = the MySQL port number of the server.

Code Sample

/**
     * Non-persistent database connection
     *
     * @access    private called by the base class
     * @return    resource
     */    
    
function db_connect()
    
{
        
if($this->port)
        
{
            
return @mysql_connect($this->hostname.':'.$this->port, $this->username, $this->password, TRUE);
        
}
        
else
        
{
            
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
        
}
    }
    
    
// --------------------------------------------------------------------

    /**
     * Persistent database connection
     *
     * @access    private called by the base class
     * @return    resource
     */    
    
function db_pconnect()
    
{
        
if($this->port)
        
{
            
return @mysql_connect($this->hostname.':'.$this->port, $this->username, $this->password, TRUE);
        
}
        
else
        
{
            
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
        
}
    }
    
    
// --------------------------------------------------------------------

Expected Result

Load the MySQL server at the configured port.

Actual Result

Works as expected under all supported versions of required platforms.

Comment on Bug Report

Page 1 of 1 pages
Posted by: nicovv on 28 July 2008 12:16am
no avatar

It would be very good when this was added, I’ve added something like this every time we’ve migrated to a new version of CodeIgniter

Posted by: Colin Williams on 6 August 2008 6:22pm
Colin Williams's avatar

I guess it’s a good idea because it minimizes the mistakes users could make. But it works just fine if you include the port in the hostname setting

Posted by: Randy Casburn on 6 August 2008 8:11pm
no avatar

Agreed…but this makes the implementation between database platforms more consistent from an end user perspective.  To switch from postgres to mysql only requires a single config change now.  As an example.

I suppose the alternative to this patch would be to make a recommendation to update the documentation to match the current code base.  The docs reflect the old code and states something like “ports are only supported by Postgres”.  Obviously this isn’t true.

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?