0

I'm running Joomla under Azure using the MySQL In-App option for the database. Everything has gone well, but I have been unable to get the database config variables in JConfig to pull dynamically from the MYSQLCONNSTR_localdb environment variable.

I've tried the MS suggested solution posted here https://blogs.msdn.microsoft.com/azureossds/2016/12/09/mysql-in-app-configuration-for-php-content-management-systems/, and have tried various ways of extracting the information from the environment variable and setting the variables to the results, all with no success. The only thing that seems to be working is hard-coding the host address which is .. problematic.

An example might be something like this:

class JConfig {
... 
$hostVar = getenv("MYSQLCONNSTR_localdb");
$hostArray = array();
foreach( explode( ';', $hostVar ) as $substr )
    {
    $asplode = explode('=', $substr);
    $hostArray[ $asplode[0] ] = $asplode[1];
    }
public $host = $hostArray['Data Source'];
...

So far all variations from the hard-coded address have been 'Error.' on the front end.

bjm
  • 33
  • 1
  • 5

1 Answers1

1

I moved the assignment to the constructor of the JConfig class. With this I'm able to dockerize it nicely.

class JConfig {

  public $smtpuser;
  public $smtppass;
  public $smtphost;
  public $host;
  public $user;
  public $password;
  public $db;
  function __construct() {
    $this->smtpuser = getenv('SMTP_USER');
    $this->smtppass = getenv('SMTP_PASSWORD');
    $this->smtphost = getenv('SMTP_HOST');
    $this->host = getenv('JOOMLA_DB_HOST');
    $this->user = getenv('JOOMLA_DB_USER');
    $this->password = getenv('JOOMLA_DB_PASSWORD');
    $this->db = getenv('JOOMLA_DB_NAME');
  }
Meiko Watu
  • 451
  • 1
  • 4
  • 11