在Azure上启用PHP扩展(php_odbc.dll) [英] Enable PHP Extension (php_odbc.dll) on Azure
问题描述
我已经开始使用Azure并测试到Microsoft SQL数据库的连接.我想利用我们当前的php_odbc.dll扩展而不是使用PDO方法.
I have started working with Azure and testing connectivity to an Microsoft SQL Database. I would like to utilize our current php_odbc.dll extension instead of using the PDO approach.
$query = "SELECT * FROM TABLE ";
//perform the query
$result=odbc_exec($conn, $query);
我已经执行了通过通过应用程序设置进行配置和通过ini设置进行配置来添加扩展程序的步骤.两种方式都会导致我的主索引页抛出500错误.我的主要index.php仅包含phpinfo();测试功能.
I have performed the steps for adding an extension by configuring via App Setting and configuring via ini settings. Both ways cause my main index page to throw a 500 error. My main index.php only includes the phpinfo(); function for testing.
问题:如何在Azure上启用php_odbc.dll ext? PHP版本是7.3
Question: How do I enable the php_odbc.dll ext on Azure? PHP version is 7.3
推荐答案
我看到您正在使用Windows的Azure WebApp通过php_odbc.dll
通过Azure SQL数据库连接部署PHP应用.
I see you were using Azure WebApp for Windows to deploy your PHP app with Azure SQL Database connection by php_odbc.dll
.
众所周知,适用于Windows的Azure WebApp已安装了具有多个扩展名的多个版本的PHP运行时,其中包括如下图所示位于路径D:\Program Files (x86)\PHP
下的PHP 7.3,并且我检查了php_odbc.dll
是否通过Kudo存在控制台https://<your webapp name>.scm.azurewebsites.net/DebugConsole
As I known, Azure WebApp for Windows has been installed several versions of PHP runtime with many extensions, which include PHP 7.3 that is under the path D:\Program Files (x86)\PHP
as the figure below and I checked php_odbc.dll
whether be exists via Kudo console https://<your webapp name>.scm.azurewebsites.net/DebugConsole
然后,我移至v7.3
以查看php.ini
文件,以检查php_odbc.dll
扩展名是否被启用.
Then, I moved to v7.3
to view the php.ini
file to check the php_odbc.dll
extension whether be enabled.
如上图所示,您可以看到在php.ini
中没有声明任何php_odbc
,因此默认情况下未启用它.而且Azure会规范D:\
下的所有文件和目录(D:\home
除外),客户无法更改这些文件和目录,因此尝试编辑php.ini
以启用php_odbc
会导致错误问题.
As the figure above, you can see there is no php_odbc
declared in php.ini
, so it's not enabled default. And Azure regulates all files and directories under D:\
(except D:\home
) that can not be changed by customers, so to try to edit php.ini
to enable php_odbc
will cause error issue.
So the solution is to refer to the section How to: Enable extensions in the default PHP runtime
of the offical document Configure PHP in Azure App Service
as the figure below to enable a default existing extension.
默认情况下,路径D:\home\site
中可能没有需要您自己创建的目录ini
,然后在其下创建一个名为extensions.ini
的文件并对其进行编辑以添加扩展名或php_odbc
的绝对路径.
By default, there may not be a directory named ini
in the path D:\home\site
which need to be created by yourself, and then to create a file named extensions.ini
under it and edit it to add the extension name or the absoluted path of php_odbc
.
; Enable Extensions
extension=php_odbc
; Or use its absoluted path, such as for 32bit platform
; extension=D:\Program Files (x86)\PHP\v7.3\ext\php_odbc.dll
重新启动Azure WebApp后,可以再次尝试PHP页面.
After restart your Azure WebApp, you can try your PHP page again.
这篇关于在Azure上启用PHP扩展(php_odbc.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!