Skip to content

Commit

Permalink
Allow custom MySQL server port number, fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetx committed Jul 28, 2014
2 parents d699544 + 58bf999 commit c69246d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ $connector->open('youruser', 'fancypass', 'holydatabase');
// not running the database on localhost? add a 4th parameter like this:
// $db->open('youruser', 'fancypass', 'holydatabase', 'pentagon.example.com');

// want persistent connection? add a 5th parameter like this:
// $db->open('youruser', 'fancypass', 'holydatabase', 'pentagon.example.com', MONTY_OPEN_PERSISTENT);
// need a custom port number? add a 5th parameter like this:
// $db->open(
// 'youruser', 'fancypass', 'holydatabase',
// 'pentagon.example.com', 3307
// );

// want a persistent connection? add a 6th parameter like this:
// $db->open(
// 'youruser', 'fancypass', 'holydatabase',
// 'pentagon.example.com', 3307, MONTY_OPEN_PERSISTENT
// );

// now there's two operation modes:
// the EASY one first
Expand Down
14 changes: 9 additions & 5 deletions classes/connector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ public abstract function nextfield();
* Monty_Connector::open()
* Open a database connection.
*
* @param string $user The database user name
* @param string $password The database password
* @param string $database Name of the database to connect to
* @param string $host Host name of database server
* @param string $user The database user name
* @param string $password The database password
* @param string $database Name of the database to connect to
* @param string $host optional, Host name of database server
* @param int $port optional, Custom port number
* @param int $open_type optional, Whether to open a persistent connection
*/
public abstract function open(
$user,
$password,
$database,
$host = 'localhost'
$host = 'localhost',
$port = 3306,
$open_type = MONTY_OPEN_NORMAL
);

/**
Expand Down
9 changes: 6 additions & 3 deletions classes/connector.mysqli.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ public function nextfield($field_data = 0)
* @param string $user The database user name
* @param string $password The database password
* @param string $database Name of the database to connect to
* @param string $host Host name of database server
* @param int $open_type Whether to open a persistent connection
* @param string $host optional, Host name of database server
* @param int $port optional, Custom port number
* @param int $open_type optional, Whether to open a persistent connection
*
* @return bool $boolIsOpened
*/
Expand All @@ -172,6 +173,7 @@ public function open(
$password,
$database,
$host = 'localhost',
$port = 3306,
$open_type = MONTY_OPEN_NORMAL
) {
$host_connectionstring = '';
Expand All @@ -192,7 +194,8 @@ public function open(
$host_connectionstring,
$user,
$password,
$database
$database,
$port
)
) {
return false;
Expand Down
8 changes: 5 additions & 3 deletions classes/monty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public static function getConnector(
* @param string $user The database user name
* @param string $password The database password
* @param string $database Name of the database to connect to
* @param string $host Host name of database server
* @param int $open_type Whether to open a persistent connection
* @param string $host optional, Host name of database server
* @param int $port optional, Custom port number
* @param int $open_type optional, Whether to open a persistent connection
*
* @return bool $boolIsOpened
*/
Expand All @@ -76,6 +77,7 @@ public static function open(
$password,
$database,
$host = 'localhost',
$port = 3306,
$open_type = MONTY_OPEN_NORMAL
) {
if (!isset(self::$objConnectors[MONTY_CONNECTOR_MYSQLI])) {
Expand All @@ -84,7 +86,7 @@ public static function open(

return self::$objConnectors[MONTY_CONNECTOR_MYSQLI]->open(
$user, $password, $database,
$host, $open_type
$host, $port, $open_type
);
}

Expand Down

0 comments on commit c69246d

Please sign in to comment.