[英]Azure web app with Laravel connection to SQL server
I have an Azure free trial account. 我有一个Azure免费试用帐户。 This is what I have in the Azure portal (everything in this list is, of course, an Azure resouce): 这就是我在Azure门户中拥有的(当然,此列表中的所有内容都是Azure资源):
Now the question is, how can I do the connection of the Laravel web app with the SQL database? 现在的问题是, 如何连接Laravel Web应用程序和SQL数据库?
Other important details: 其他重要细节:
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. 我什至没有尝试安装它,因为我的“实际使用”将来自Azure上的Laravel网站。
<?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);
?>
I dont know why you are using this code in laravel. 我不知道您为什么在laravel中使用此代码。
For Sql Server Connection laravel provides drivers, use that for your case it will be: 对于Sql Server Connection,laravel提供了驱动程序,在您的情况下使用它将是:
In config folder > databse file edit these : 在配置文件夹>数据库文件中编辑以下内容:
'default' => env('DB_CONNECTION', 'mysql'),
to 'default' => env('DB_CONNECTION', 'mysql'),
'default' => 'sqlsrv',
if you dont want to use env file vars else update env var to reflect the same. 如果您不想使用env文件vars,请更新env var以反映相同的内容。
update this driver values: 'connections' => [ 'sqlsrv' => [,
更新此驱动程序值: 'connections' => [ 'sqlsrv' => [,
And for more help on deploying laravel app on azure check this: https://medium.com/@coderonfleek/hosting-a-laravel-application-on-azure-web-app-b55e12514c46 有关在天蓝色上部署laravel应用的更多帮助,请查看以下网址 : https ://medium.com/@coderonfleek/hosting-a-laravel-application-on-azure-web-app-b55e12514c46
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.