I have an Azure free trial account. This is what I have in the Azure portal (everything in this list is, of course, an Azure resouce):
- PHP web app with a working Laravel framework installed
- The web app is connected (and update itself) to a Bitbucket repository
- A SQL database (and the related SQL server)
Now the question is, how can I do the connection of the Laravel web app with the SQL database?
Other important details:
- In the solution, I would like to stick we the free plan (so, please, no solution involving a changing in the Azure plan);
- I tried to do the connection locally (from a sample code that I got online) but I was not able because of this error:
PHP Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()
I discovered that this error was because I don't have this driver installed locally. I didn't even try to install it because my "real use" will be from the Laravel website on Azure.
<?php
$serverName = "****.database.windows.net";
$connectionOptions = array(
"Database" => "****",
"Uid" => "admin-****",
"PWD" => "#####"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
$tsql= "SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
FROM [SalesLT].[ProductCategory] pc
JOIN [SalesLT].[Product] p
ON pc.productcategoryid = p.productcategoryid";
$getResults= sqlsrv_query($conn, $tsql);
echo ("Reading data from table" . PHP_EOL);
if ($getResults == FALSE)
echo (sqlsrv_errors());
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
echo ($row['CategoryName'] . " " . $row['ProductName'] . PHP_EOL);
}
sqlsrv_free_stmt($getResults);
?>