1

I am working in a project which consist on deploying PHP web site in Azure and connecting with an Azure MySQL.

I started by creating and migrating the data in Azure MySQL. I also created the PHP web site and deployed the code but when added the connection string on configuration part of the web app it gives me an error:

value is a required property on all connection strings

the connection string:

$con=mysqli_init(); [mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);] mysqli_real_connect($con, {your_host}, {username@servername}, {your_password}, {your_database}, {your_port});

I cannot save the connection string because the error is in red below the tab of the connection string.

Because I don't have experience with PHP and MySQL I googled the error but haven't found anything.

12
  • You do not pass key and certificate path Commented Sep 7, 2019 at 19:15
  • Can you explain please. Commented Sep 7, 2019 at 20:01
  • You pass lots off NULL as parameter, I don't think it will work Commented Sep 7, 2019 at 20:10
  • I copied this connection string from the MySQL db. I added the server, dbname, userId and the password. How can be a connection string without the null in PHP? Commented Sep 7, 2019 at 20:16
  • 1
    @JoePlatano yes I solved incorporated the connection in a file not in azure and fixed. Commented Sep 17, 2020 at 16:07

1 Answer 1

2

If you want to add my sql connection string in Azure web app, please refer to the following step

  1. Get connection string enter image description here

  2. Add connection string in Azure web app enter image description here

  3. Enable access from an Azure App Service to an Azure Database for MySQL

    Azure Database for MySQL provides access security using a firewall to protect your data. When connecting from an Azure App Service to Azure Database for MySQL server, keep in mind that the outbound IPs of App Service are dynamic in nature. Choosing the "Allow access to Azure services" option will allow the app service to connect to the MySQL server. enter image description here

  4. upload perm file via kudu enter image description here

  5. Connect Azure MySQL with php

<?php
$connectstr_dbhost = '';
$connectstr_dbname = '';
$connectstr_dbusername = '';
$connectstr_dbpassword = '';
foreach ($_SERVER as $key => $value) {
    if (strpos($key, "MYSQLCONNSTR_") !== 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);
}

$conn = mysqli_init();
mysqli_ssl_set($conn,NULL,NULL, "D:/home/site/wwwroot/Cert/BaltimoreCyberTrustRoot.crt.pem", NULL, NULL) ;
mysqli_real_connect($conn, $connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword, $connectstr_dbname, 3306, MYSQLI_CLIENT_SSL);
if (mysqli_connect_errno($conn)) {
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
echo "Success: A proper connection to MySQL was made! The  database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($conn) . PHP_EOL;

?>

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I have used this connection string $con=mysqli_init(); [mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);] mysqli_real_connect($con, {your_host}, {username@servername}, {your_password}, {your_database}, {your_port}); . You have used the other, can you explain please the difference.
have you configured SSL for Azure mysql(learn.microsoft.com/bs-latn-ba/Azure/mysql/howto-configure-ssl)? If you do not configure it, you can use my code.
The app is ready works in development just I need to connect the db. I want just the connection. If you have experience with php & MySQL please write the connection string that works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.