Connect to Azure SQL database with PHP - php

I try to connect to my azure database only with the provided connection string. However I just get this error message:
Error connecting to SQL Server.PDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\XAMPP\htdocs\folder\Databaseconnection.php [line:protected] => 4 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\XAMPP\htdocs\folder\Databaseconnection.php [line] => 4 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => sqlsrv:server = tcp:{server}.database.windows.net,1433; Database = testdb [1] => {username} [2] => {password} ) ) ) [previous:Exception:private] => [errorInfo] => ) 1
The servername username and password is obviously changed here. I also allowed my own IP adress on the server firewall settings. Any help appriciated.

The reason is caused by that you want to use PHP PDO to connect Azure SQL Database, but the error information shows there is not a PHP driver to support SQL Azure connection.
You could reference this blog:Error connecting to SQL Server.PDOException Object (Azure).
You need to refer to the section PHP Version Support of the offical document Microsoft PHP Drivers for SQL Server Support Matrix to know what version of PHP PDO driver for Azure SQL Database is for PHP v7.4:
Please choose the suitable PHP version and SQL Server driver.
You could Download the Microsoft Drivers for PHP for SQL Server for your system. Also reference Production Release for the PHP drivers Version 5.6.0 for SQL Server.
Hope this helps.

Related

PHP SQLSRV Error using machine account

I am using SQLSRV function using windows authentication but it is using the machine account as a default. How can I change it? I want to run using HOMESBUILD\john.davis
I am running PHP 5.3.10 on WAMP Server 2.2
Error Message:
Connection could not be established.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'HOMESBUILD\KKK-454-IAH05$'.
I had to configure the WAMP server from Services to run as different account.

Using ODBC Driver 13 instead of ODBC Driver 11 to Connect to SQL Server 2008 R2

I am trying to connect to my MS SQL Server (2008 R2) with php and xampp. Upon running the code I got this error:
Connection could not be established.Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -49
[code] => -49
[2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
)
[1] => Array
(
[0] => IM002
[SQLSTATE] => IM002
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
)
)
So, I decided to try to install the ODBC Driver 11. I could not install the driver on Windows 10 because it's not supported so I downloaded ODBC Driver 13 and it still did not work. Is there a way I can reconfigure ODBC Driver 13 so it will work in replace of ODBC Driver 11? If there is anything else I can provide that would be useful let me know. I cannot use MySQL for this, nor can I update SQL Server.
PHP SQL Server Couldn't connect
PHP 5.5 and MSSQL driver: Installing ODBC Driver 11 in Windows Server 2012 R2
To make an addition, make sure you installed the correct version (32-bit vs 64 bit) of ODBC!
Know which version your system runs: your SQL server might be a different version.
Even if these questions don't solve it directly, they might contain useful information for your situation.
Refer to these questions; I think you should be able to find a solution.
The DLL file of ODBC might need to be copied under your working directory of PHP in addition to being installed.
I see that being a common problem with JDBC at least.
Good luck!

Connecting to database on SQL server from WAMPSERVER 2.5

I've got a WAMPSERVER 2.5 development server. It's running PHP 5.512.
I'm trying to connect to our live SQL Server. I've installed and activated the version 32 files, and used the following code:
<?php
$link = sqlsrv_connect('obscured_ip:obscured_port', array('Database'=>'obscured_database','UID'=>'obscured_uid', 'PWD'=>'obscured pwd'));
if (!$link)
die(print_r(sqlsrv_errors(), true));
?>
I'm getting the following error:
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP 1 => -49 [code] => -49 2 => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) 1 => Array ( [0] => IM002 [SQLSTATE] => IM002 1 => 0 [code] => 0 2 => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )
The link specified there just takes me back to the driver download page. What am I doing wrong?
The URL in the error points to the wrong page. This is the correct one: https://www.microsoft.com/en-us/download/details.aspx?id=36434

PHP MsSQL WAMP - Couldn't connect to MSSQL

I've downloaded SQLSRV32.EXE from the official MSSQL Driver for PHP and extracted php_sqlsrv_56_ts.dll & php_pdo_sqlsrv_56_ts.dll into C:\wamp\bin\php\php5.6.19\ext
Added the following declaration in the php.ini from the WAMP menu.
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_ts.dll
I then run the sample code from the reference page.
I couldn't connect to the MS SQL Server due to the following error
Connection could not be establish
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )
I've tried to download the ODBC Driver 13 (for Windows 10) but it is not working. Can someone tell me what I'm doing wrong?
As I can see - ODBC Driver 13 is not supported on your system and the required one is ODBC Driver 11.
https://www.microsoft.com/en-us/download/details.aspx?id=36434

Can anyone decipher an error message I get when trying to store form data on MS SQL using php?

I attempted to connect to an Microsoft SQL database and store html form data in it using php but was unable to.
At first I attempted using the mssql syntax but realized that it was abandoned past 5.2 (I'm running 5.3). Then I attempted to connect using the sqlsrv syntax but that required a driver and editing the php.ini file -- which I did only to receive this error message pertaining to the MS SQL Native Client:
> Connection COULD NOT be establishedArray ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )
A phpinfo file shows that sqlsrv is installed and I've deleted and reinstalled the drivers and native client twice already to no avail..........
Here is the stack:
Windows 2003 server
IIS 6 web host
local install of MS SQL 2008 (previously was attempting to connect to a remote MS SQL 2014 database
PHP version 3.1.3

Categories