GOAL: To use a PHP webjob to connect and alter SQL database table in Azure.
I'm trying to upload a .zip
file containing a .php
and a .json
file to the webjobs settings inside of an app service I have running on Azure.
I believe there's something wrong with the way I'm coding the PDO-SQL connection inside of the PHP file, when I upload the webjob as a .zip
into webjobs, the Status is always "Pending Restart".
Here's what I have in my .php
file:
<?php
$conn = new PDO ( "sqlsrv:server = mydb.database.windows.net,1433; Database = myappservices");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
catch ( PDOException $e ) {
print( "Error connecting to SQL Server." );
}
$connectionInfo = array("Database" => "myappservices");
$serverName = "mydb.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
$stf = $conn->prepare("INSERT INTO MyTable
VALUES ('boom', 1, 2);");
$stf->execute();
}
?>
Then my .json
file is just a scheduler:
{
"schedule": "0 */5 * * * *"
}
These are the only two files in my .zip
file I'm uploading.
To explain the PHP code, I'm trying to connect via windows authentication (no need for user/pass). Maybe I'm doing this wrong too.
Anyone have any ways to do this? I would really appreciate giving a step by step or suggestions as to how to change my code to get this webjob to actually run.