-1

Having trouble connecting to my Azure Database for MySQL. Here is my PHP code:

class access {

    var $user = "##";
    var $pass = "##";
    var $conn = null;
    var $result = null;
    var $StudentID = null;
    var $sql = null;

    public function connect() {
        $this->conn = new mysqli( host: 'autosign.database.windows.net', username: '##', passwd: '##', dbname: 'Automat');
        if (mysqli_connect_error()){
            echo 'Could not connect to database';
        } else {
            echo 'Connected and Selected';
        }
    }
}

I am using XAMMP to run the PHP scripts. I am using a template app and therefore cannot use a default Azure app connect, and I have been unsuccessful in using the downloadable Azure framework.

ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69
  • 1
    Hi there, welcome to SO. It is really hard for us to be of help, can you tell us more about what troubles you have (do you get any errors) and why you can't use the downloadable framework? – Peter Bons Apr 27 '18 at 18:49
  • 2
    I pulled your code out of the image into the question. Next time try to include all the relevant code in the question, not in screenshots. It makes it easier for people to take your code and test it :) – juunas Apr 27 '18 at 20:23

1 Answers1

1

My first instinct tells me that your Azure Database for MySQL is configured to require SSL, and your code is not using it.

You have two options:

  1. Disable SSL requirement (not recommended)
  2. Configure your PHP code so it's connecting using SSL

Documentation for doing both #1 and #2 is here, with code samples: https://learn.microsoft.com/en-us/azure/mysql/howto-configure-ssl#php

In short:

Download the SSL CA certificate from https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem and put it in the folder with your PHP code. Then, edit the connection so it's like (copied from the docs):

$conn = mysqli_init();
mysqli_ssl_set($conn, NULL, NULL, "/path/to/your/cert/BaltimoreCyberTrustRoot.crt.pem", NULL, NULL); 
mysqli_real_connect($conn, 'autosign.mysql.database.azure.com', $user, $pass, 'Automat', 3306, MYSQLI_CLIENT_SSL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
ItalyPaleAle
  • 7,185
  • 6
  • 42
  • 69