Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Change database port?

Post Reply
Giu
Posts: 71
Joined: Sat Jan 25, 2014 11:01 am

Change database port?

Unread post by Giu »

Hi all,

I revisiting nuBuilder. I installed on my machine, but I have MariaDB running on port 3307. Where can I change this in config?

Regards.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Change database port?

Unread post by massiws »

Giu,
below is a patch to add the DB port configuration into nuBuilderPro: apply these changes and set the port number in config.php file.

@Steven: I removed line 21 in index.php because it's not necessary.

Hope this helps,
Max.

Code: Select all

diff --git a/config.php b/config.php
index 941c517..dc93aff 100644
--- a/config.php
+++ b/config.php
@@ -1,6 +1,7 @@
 <?php
 
     $nuConfigDBHost                 = "127.0.0.1";
+    $nuConfigDBPort                 = "3306";
     $nuConfigDBName                 = "site_c";
     $nuConfigDBUser                 = "root";
     $nuConfigDBPassword             = "root";
diff --git a/index.php b/index.php
index 9bfb519..b93729d 100644
--- a/index.php
+++ b/index.php
@@ -16,7 +16,6 @@
 <script src="ace/ace.js" type="text/javascript" charset="utf-8"></script>
 
 <?php
-require_once('config.php');
 require_once('nucommon.php');
 
 jsinclude('nuformat.js');
diff --git a/nucommon.php b/nucommon.php
index 257afca..8ad5626 100644
--- a/nucommon.php
+++ b/nucommon.php
@@ -5,6 +5,7 @@ require_once('config.php');
 session_start();
 
 $_SESSION['DBHost']                 = $nuConfigDBHost;
+$_SESSION['DBPort']                 = $nuConfigDBPort;
 $_SESSION['DBName']                 = $nuConfigDBName;
 $_SESSION['DBUser']                 = $nuConfigDBUser;
 $_SESSION['DBPassword']             = $nuConfigDBPassword;
diff --git a/nudatabase.php b/nudatabase.php
index bcf1a59..598136f 100644
--- a/nudatabase.php
+++ b/nudatabase.php
@@ -5,11 +5,12 @@ require_once('nucommon.php');
 mb_internal_encoding('UTF-8');
 
 $DBHost                      = $_SESSION['DBHost'];
+$DBPort                      = $_SESSION['DBPort'];
 $DBName                      = $_SESSION['DBName'];
 $DBUser                      = $_SESSION['DBUser'];
 $DBPassword                  = $_SESSION['DBPassword'];
 
-$nuDB = new PDO("mysql:host=$DBHost;dbname=$DBName;charset=utf8", $DBUser, $DBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
+$nuDB = new PDO("mysql:host=$DBHost;port=$DBPort;dbname=$DBName;charset=utf8", $DBUser, $DBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
 $nuDB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
 $GLOBALS['nuSetup']          = db_setup();
diff --git a/nuinstall.php b/nuinstall.php
index 7ec905c..4d82224 100644
--- a/nuinstall.php
+++ b/nuinstall.php
@@ -5,6 +5,7 @@
         session_start();
 
         $_SESSION['DBHost']                 = $nuConfigDBHost;
+        $_SESSION['DBPort']                 = $nuConfigDBPort;
         $_SESSION['DBName']                 = $nuConfigDBName;
         $_SESSION['DBUser']                 = $nuConfigDBUser;
         $_SESSION['DBPassword']             = $nuConfigDBPassword;
@@ -12,7 +13,7 @@
         $_SESSION['title']                  = $nuConfigtitle;
 
         $template = new nuinstall();
-        $template->setDB($_SESSION['DBHost'], $_SESSION['DBName'], $_SESSION['DBUser'], $_SESSION['DBPassword']);
+        $template->setDB($_SESSION['DBHost'], $_SESSION['DBPort'], $_SESSION['DBName'], $_SESSION['DBUser'], $_SESSION['DBPassword']);
 	$template->checkInstall();
 ?>
 
@@ -114,7 +115,7 @@
 	if ( isset($_POST['pwd']) &&  $_POST['pwd'] == $_SESSION['DBGlobeadminPassword'] ) {
 
 		$template       = new nuinstall();
-        	$template->setDB($_SESSION['DBHost'], $_SESSION['DBName'], $_SESSION['DBUser'], $_SESSION['DBPassword']);
+        	$template->setDB($_SESSION['DBHost'], $_SESSION['DBPort'], $_SESSION['DBName'], $_SESSION['DBUser'], $_SESSION['DBPassword']);
 		$template->checkInstall();
 
 		if ( $_POST['overrideSetup'] == "y" ) {
diff --git a/nuinstall_lib.php b/nuinstall_lib.php
index 24f9131..c390e3f 100644
--- a/nuinstall_lib.php
+++ b/nuinstall_lib.php
@@ -35,8 +35,9 @@ class nuinstall {
 		}
 	}
 
-        function setDB($DBHost, $DBName, $DBUserID, $DBPassWord) {
+    function setDB($DBHost, $DBPort, $DBName, $DBUserID, $DBPassWord) {
         $this->DB['DBHost']       = $DBHost;
+        $this->DB['DBPort']       = $DBPort;
         $this->DB['DBName']       = $DBName;
         $this->DB['DBUserID']     = $DBUserID;
         $this->DB['DBPassWord']   = $DBPassWord;
@@ -45,12 +46,13 @@ class nuinstall {
 	function checkDatabaseConnection() {
 
         $DBHost         = $this->DB['DBHost'];
+        $DBPort         = $this->DB['DBPort'];
         $DBUserID       = $this->DB['DBUserID'];
         $DBPassWord     = $this->DB['DBPassWord'];
         $DBName         = $this->DB['DBName'];
 
 		$con = false;
-                $con = mysql_connect($DBHost,$DBUserID,$DBPassWord);
+        $con = mysql_connect($DBHost.':'.$DBPort, $DBUserID, $DBPassWord);
         if ($con === false) {
 			return false;
                 } else {
@@ -61,11 +63,12 @@ class nuinstall {
 	function checkDatabaseExists() {
 
         $DBHost         = $this->DB['DBHost'];
+        $DBPort         = $this->DB['DBPort'];
         $DBUserID       = $this->DB['DBUserID'];
         $DBPassWord     = $this->DB['DBPassWord'];
         $DBName         = $this->DB['DBName'];
 
-                $con = mysql_connect($DBHost,$DBUserID,$DBPassWord);
+        $con = mysql_connect($DBHost.':'.$DBPort, $DBUserID, $DBPassWord);
 
 		$sdb = mysql_select_db($DBName,$con);
 
@@ -541,11 +544,12 @@ class nuinstall {
 	function runQuery($pSQL, $dbInfo) {
 
 		$DBHost 	= $dbInfo['DBHost'];
+        $DBPort     = $dbInfo['DBPort'];
 		$DBUserID	= $dbInfo['DBUserID'];
 		$DBPassWord = $dbInfo['DBPassWord'];
 		$DBName		= $dbInfo['DBName'];
 
-                $con = mysql_connect($DBHost,$DBUserID,$DBPassWord) or die ("Could not connect to database\n");
+        $con = mysql_connect($DBHost.':'.$DBPort, $DBUserID, $DBPassWord) or die ("Could not connect to database\n");
         mysql_select_db($DBName,$con) or die ("Could not select database\n");
         $t = mysql_query($pSQL);
 
diff --git a/nupmalogin.php b/nupmalogin.php
index 4892a2a..77f81cc 100644
--- a/nupmalogin.php
+++ b/nupmalogin.php
@@ -2,7 +2,7 @@
 require_once('config.php');
 $session_id = $_REQUEST['sessid'];
 
-$db = new PDO("mysql:host=$nuConfigDBHost;dbname=$nuConfigDBName;charset=utf8", $nuConfigDBUser, $nuConfigDBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
+$db = new PDO("mysql:host=$nuConfigDBHost;port=$nuConfigDBPort;dbname=$nuConfigDBName;charset=utf8", $nuConfigDBUser, $nuConfigDBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $values = array($session_id, 'globeadmin');
 $sql = "SELECT * FROM zzzsys_session WHERE zzzsys_session_id = ? AND sss_zzzsys_user_id = ?";
@@ -27,7 +27,7 @@ if ( $result == 1 ) {
 		$_SESSION['PMA_single_signon_user']             = $nuConfigDBUser;
 		$_SESSION['PMA_single_signon_password']         = $nuConfigDBPassword;
 		$_SESSION['PMA_single_signon_host']             = $nuConfigDBHost;
-		$_SESSION['PMA_single_signon_port']             = "3306";
+		$_SESSION['PMA_single_signon_port']             = $nuConfigDBPort;
 		$page = 'phpmyadmin/index.php?server=1';
 	}
 }
diff --git a/nuupdatesch.php b/nuupdatesch.php
index 8e61f2f..1bd9744 100644
--- a/nuupdatesch.php
+++ b/nuupdatesch.php
@@ -93,6 +93,7 @@
 		$nuupdatesch 			= new nuupdatesch();
 
         $nuupdatesch->DBHost        = $nuConfigDBHost;
+        $nuupdatesch->DBPort        = $nuConfigDBPort;
 		$nuupdatesch->DBName 		= $nuConfigDBName;
 		$nuupdatesch->DBUserID 		= $nuConfigDBUser;
 		$nuupdatesch->DBPassWord 	= $nuConfigDBPassword;
diff --git a/nuupdatesch_lib.php b/nuupdatesch_lib.php
index 2807914..9d8e1a7 100644
--- a/nuupdatesch_lib.php
+++ b/nuupdatesch_lib.php
@@ -45,7 +45,7 @@ class nuupdatesch {
 
 	function runQuery($pSQL) {
 
-                $con 		= mysql_connect($this->DBHost, $this->DBUserID, $this->DBPassWord) or die ("Could not connect to database\n");
+                $con 		= mysql_connect($this->DBHost.':'.$this->DBPort, $this->DBUserID, $this->DBPassWord) or die ("Could not connect to database\n");
                 mysql_select_db($this->DBName,$con) or die ("Could not select database\n");
                 $rs 		= mysql_query($pSQL);
 
Giu
Posts: 71
Joined: Sat Jan 25, 2014 11:01 am

Re: Change database port?

Unread post by Giu »

Thanks a lot Max. Could be interesting to have this option in config, but looking into your code, I tried with

Code: Select all

    $nuConfigDBHost                 = "127.0.0.1:3307";
And it works. It's curious, I tried this too before my message, but didn't worked, maybe some problem on my apache local instance, because now I'm under another WAMP system and worked.

Thanks agin.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Change database port?

Unread post by massiws »

Giu,
DB connections in nuBuiderPro are managed with PHP PDO that require specific syntax in DNS connection string.
But in some parts of the code (ie, in nuinstall.php), nuBuilderPro is still using the old mysql_connect() function: so, to run initial install script your method is ok, but on CRUD operations you may have some problems.

Max
Post Reply