Skip to content
Advertisement

Enable PHP Extension (php_odbc.dll) on Azure

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); 

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.

https://docs.microsoft.com/bs-latn-ba/azure/app-service/web-sites-php-configure#configure-via-app-setting

Question: How do I enable the php_odbc.dll ext on Azure? PHP version is 7.3

Advertisement

Answer

I see you were using Azure WebApp for Windows to deploy your PHP app with Azure SQL Database connection by php_odbc.dll.

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

enter image description here

Then, I moved to v7.3 to view the php.ini file to check the php_odbc.dll extension whether be enabled.

enter image description here

enter image description here

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.

enter image description here

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.

enter image description here

By default, there may not be a directory named ini in the path D:homesite 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)PHPv7.3extphp_odbc.dll

After restart your Azure WebApp, you can try your PHP page again.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement