I've made a simple Azure function that when executed will run an insert query to a MySQL database. The MySQL database lives on a HostGator server (shared plan). The Azure function I wrote is able to insert to the DB table as expected when running locally, but after I deploy to Azure the function appears to run fine, but then no new records show in the database table.
Below is the function code:
const mysql = require('mysql');
module.exports = async function (context, req) {
var connection = mysql.createConnection({
host: '*****************',
user: '*************',
password: '*************',
database: '***************'
});
connection.connect();
const insertQuery = `INSERT into emails (email_address, first_name, last_name, preferred_game, date_joined) VALUES ('[email protected]', 'Bob', 'Jones', 'both', NOW());`;
await connection.query(insertQuery, function (error, results, fields) {
if (error) throw error;
});
connection.end();
context.res = {
// status: 200, /* Defaults to 200 */
body: '200'
};
}
The strange thing is that I don't see any errors in the logs anywhere, so it appears to work, but when I look in the DB no new records have been inserted. I thought at first it might be an IP whitelist issue, but after adding the Azure Function App IP it still failed to insert a record to the DB (Virtual IP as shown under app properties in the Azure portal).
I can't think of why else this wouldn't be able to insert records to the DB from the deployed Azure function.

context.logto trace if the function is actually running firstly and then if it is and the connection is a problem, there'll be an error message that may help