From 36fc81aa21eeadcd8a044f266855d840c33d1c01 Mon Sep 17 00:00:00 2001 From: "J.M" Date: Mon, 28 Jul 2014 20:16:33 +0200 Subject: [PATCH 1/2] Add custom port number parameter to Monty::open --- classes/connector.class.php | 14 +++++++++----- classes/connector.mysqli.class.php | 9 ++++++--- classes/monty.class.php | 8 +++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/classes/connector.class.php b/classes/connector.class.php index 4a3631d..48379d7 100644 --- a/classes/connector.class.php +++ b/classes/connector.class.php @@ -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 ); /** diff --git a/classes/connector.mysqli.class.php b/classes/connector.mysqli.class.php index aca6ac5..c8b4033 100644 --- a/classes/connector.mysqli.class.php +++ b/classes/connector.mysqli.class.php @@ -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 */ @@ -172,6 +173,7 @@ public function open( $password, $database, $host = 'localhost', + $port = 3306, $open_type = MONTY_OPEN_NORMAL ) { $host_connectionstring = ''; @@ -192,7 +194,8 @@ public function open( $host_connectionstring, $user, $password, - $database + $database, + $port ) ) { return false; diff --git a/classes/monty.class.php b/classes/monty.class.php index cf12f78..b2fb707 100644 --- a/classes/monty.class.php +++ b/classes/monty.class.php @@ -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 */ @@ -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])) { @@ -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 ); } From 58bf99953ac23f4bd08c3ba592d9ff73273f798a Mon Sep 17 00:00:00 2001 From: "J.M" Date: Mon, 28 Jul 2014 20:16:46 +0200 Subject: [PATCH 2/2] Add README entry for custom port numbers --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ee7b5c..8660918 100644 --- a/README.md +++ b/README.md @@ -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