title: How to use Mysql Connection String inside PHP code which is served by Azure Lunix App Service
body: <p>I'm trying to host Wordpress to Azure lunix App service.</p>
  
  <p>I created a Azure Database for MySQL, then I got the web app connection string from the connection strings screen.</p>
  
  <p><a href="https://i.stack.imgur.com/mIm84.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mIm84.png" alt="Azure Database for MySQL Connection Strings"></a></p>
  
  <p>The connection string format is</p>
  
  <pre><code>Database={your_database}; Data Source={data_source}; User Id= {user_id}; Password={your_password}
  </code></pre>
  
  <p>Then I created a Linux based app service and added the MySQL connection string to its configuration.</p>
  
  <p><a href="https://i.stack.imgur.com/1q8uX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1q8uX.png" alt="App service Configuration"></a></p>
  
  <p>Then I used this code in <code>wp-config.php</code> to get the Database connection string form the PHP environment variable <code>MYSQLCONNSTR_bridgesConnection</code></p>
  
  <pre><code>&lt;?php
  
  $connectstr_dbhost = '';
  $connectstr_dbname = '';
  $connectstr_dbusername = '';
  $connectstr_dbpassword = '';
  
  foreach ($_SERVER as $key =&gt; $value) {
      echo $key ;
   if (strpos($key, "MYSQLCONNSTR_bridgesConnection") !== 0) {
   continue;
   }
  
  
   $connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $value);
   $connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value);
   $connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\\1", $value);
   $connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\\1", $value);
  }
  </code></pre>
  
  <p>That code works if you are using windows App service. But If you are using Linux App service you will get this warning and the wordpress won't work</p>
  
  <blockquote>
    <p>Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /wordpress/wp-includes/wp-db.php on line 1452</p>
  </blockquote>
  
  <p>I created a php info page using this code</p>
  
  <pre><code>&lt;?php
  phpinfo();
  ?&gt;
  </code></pre>
  
  <p>I'm sure that the PHP environment variable is loaded but I need a way to access it.</p>
  
  <p><a href="https://i.stack.imgur.com/OYnAo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OYnAo.png" alt="PHP info page"></a></p>
  
  <p>How to access that connection string in PHP code?</p>