makeusabrew/jaoss

Allow the database class to connect to remote hosts on custom ports

Closed this issue · 2 comments

I was working on a new application that was to be hosted on heroku and needed to implement a database so I chose to use the xeround the cloud service. It's really good (another topic) but it requires a non-standard port - something that JAOSS doesn't support out of the bag.

I've modded a local version to allow this application to work, however I'd suggest that something like the following is used (obviously your better judgement will prevail here....)

if(Settings::getValue("db", "port", false)){
  $dsn = "mysql:dbname=".Settings::getValue("db", "dbname").";host=".Settings::getValue("db", "host").";port=". Settings::getValue("db", "port");
 }
else{
  $dsn = "mysql:dbname=".Settings::getValue("db", "dbname").";host=".Settings::getValue("db", "host");
}

You're absolutely right - it does need to support a custom port. Will get this implemented asap.

I've eventually gone with the following as it felt more robust.

if(Settings::getValue('db', 'port', false) && Settings::getValue('db', 'port') !== ''){
  $dsn = "mysql:dbname=".Settings::getValue("db", "dbname").";host=".Settings::getValue("db", "host").";port=".Settings::getValue("db", "port");
}
else{
  $dsn = "mysql:dbname=".Settings::getValue("db", "dbname").";host=".Settings::getValue("db", "host");
}

As another thought, it might be worth also allowing a custom driver to be defined too, just in case the database needs to run on, for example, PostgreSQL