Connecting to database on SQL server from WAMPSERVER 2.5 - php

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

Related

Cannot connect to SQL Server with PHP script

I run SQL Server 2016. I try to connect to it via a PHP script (PHP version 8). I did install the drivers and added the path in the php.ini (same version as my PHP version):
...
extension=pdo_sqlsrv_80_nts
extension=pdo_sqlsrv_80_ts
extension=sqlsrv_80_nts
extension=sqlsrv_80_ts
...
Here is my script:
$serverName = "<ServerName>";
$connectionInfo = array( "Database"=>"<database>", "UID"=>"<user>", "PWD"=>"<pwd>");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
I get the following error:
Array
(
[0] => Array
(
[0] => IM006
[SQLSTATE] => IM006
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
[message] => [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
)
[1] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5701
[code] => 5701
[2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed database context to '<database>'.
[message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed database context to '<database>'.
)
[2] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5703
[code] => 5703
[2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed language setting to us_english.
[message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Changed language setting to us_english.
)
)
Any idea what could be wrong?
Thank you for your help
I had the same issue after upgrading from Php 7 to 8. My PDO code (pdo_sqlsrv) still worked, as some of the commenters here mention. But the old non-PDO code (sqlsrv) got the same error that you describe.
I started switching that code over to PDO, and will continue that when I can. But I then realized that updating my SQL Server drivers resolved the issue. You can find those drivers by googling "Download ODBC Driver for SQL Server". You will be wanting verion 17 or above.
I recently stumbled upon this same issue. For me sqlsrv_query was throwing warnings as errors. I fixed this by putting sqlsrv_configure('WarningsReturnAsErrors',0); just above the query code.
Update:
You need to update your ODBC driver's version. According to this article, there are known issues with driver below 17.4.2.
Download latest ODBC
here.
Update 2:
If you are using PHP driver 5.9, then ODBC driver 18 will be incompatible. Refer here. You must have ODBC driver 17(higher then 17.4.2) as well.
Been stuck on this exact issue for days until the keywords "upgrade odbc driver" hit me. As soon as I've upgraded, the issue was fixed. https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15

ODBC Driver 11 for SQL Server

I'm using the SQL Server 2008 installed in a remote desktop. And I am trying to access it using PHP.
I have downloaded the PHP drivers. The Registered PHP Streams in phpinfo includes sqlsrv.
So if the following error pops the ODBC driver should be installed in my system or in remote desktop. I'm using PHP Version 7.0.8, so I need ODBC Driver 11 or 13?
Connection failureArray
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -49
[code] => -49
[2] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
[message] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 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
)
)

PHP: ODBC 11 does not support connections to sql server 2000 or earlier version

I'm trying to connect to MS SQL using sqlsrv_connect, before I installed ODBC 11 I got error that required to install ODBC 11 so I installed it. After i Install I got another error message again
Array
(
[0] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => 22
[code] => 22
[2] => [Microsoft][ODBC Driver 11 for SQL Server]ODBC Driver 11 for SQL Server does not support connections to SQL Server 2000 or earlier versions.
[message] => [Microsoft][ODBC Driver 11 for SQL Server]ODBC Driver 11 for SQL Server does not support connections to SQL Server 2000 or earlier versions.
)
[1] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => 22
[code] => 22
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Client unable to establish connection
[message] => [Microsoft][ODBC Driver 11 for SQL Server]Client unable to establish connection
)
)
Is this possible to connect these connections?
function access_store($ips){
$conInfo = array("Database"=>"site5");
$conn = sqlsrv_connect($ips, $conInfo);
if($conn){
echo'Connection SUccess';
}else{
die('<pre>'.print_r( sqlsrv_errors(),true ).'</pre>');
}
}
What version Microsoft PHP sql driver installed? You need an older version of the driver.
Tech republic has a good article
Tech republic
Microsoft SQL server driver

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