This snippet shows you how to connect to Azure database for you to run some scripts for an example. In this example we use ODBC class not through PDO. You need to download two packages from your repository or if you are using a distribution where they are not in repository you need to get them from some third party. The packages are msodbcsql and php_odbc. Also you need to enable odbc from php.ini file.
Get packages
Get packages called msodbcsql and php_odbc from repositories or if your distribution doesn't have them, from third party.Configure php.ini
Enable php-odbc from php.ini file, by uncommenting line "extension=odbc".Source code viewer
extension=odbcProgramming Language: INI
Connect to database.
Source code viewer
'Driver={ODBC Driver 17 for SQL Server};'. 'Server=tcp:[YOUR_DOMAIN].database.windows.net,1433;'. 'Database=[YOUR_DATABASE];'. 'Encrypt=yes;'. 'TrustServerCertificate=no;'. 'Connection Timeout=30;', '[YOUR_USERNAME]', '[YOUR_PASSWORD]'); if ($db) { if (!$success) { } // ... } else { } Programming Language: PHP
"Escape" strings
Using the method above to run queries, you have to escape your strings. If the string as preceeding or appending single quote(') then the function tries to get the cell content from a file. This is a working workaround for that.Source code viewer
foreach ($fields_values as $key => $val) { $fields_values[$key] .= ' '; } }Programming Language: PHP