I have XAMPP running on an MS Server 2012 R2. I need to make a connection to an MSSQL server which accepts only integrated win authentication.
If I simply try the below, I get a login failure and an error log on the SQL Server that SQL authentication is not an option. It only accepts connection from a certain user. Obviously the PHP script is not being run under that account.
$server = "sqlServerName";
$SQLUser = "username";
$SQLPass = "pw";
$SQLDatabase = "db";
$link = mssql_connect($server,$SQLUser,$SQLPass);
As I'm using PHP 5.3.1 sqlsrv_connect
is not an option. I tried to load the php drivers for it but it's just not working. I can't change the authentication for the sql server and I can't use any other version of PHP.
I also can't turn the secure_connection on as I have to be able to connect to other sql servers which requires "normal" sql authentication:
mssql.secure_connection = Off
How to connect to my problematic sql server?
UPDATE: Upgraded xampp
to the latest version. PHP
is now version 5.6.8
I still can't use sqlsrv_connect()
even though I installed the necessary driver and added every single dll to the php.ini
. Restarted apache
several times. Any clue?
error msg: Fatal error: Call to undefined function sqlsrv_connect()
Ok. It's hard to debug a server issue without being on the server but I've done a lot with php and SQL Server so I will do my best to share my experiences.
First, Very glad you updated from 5.3.1 that version of php is ancient and very insecure. Here are some sanity checks for your system. This may do nothing for you but all of it is worth checking.
First make sure you can connect to sql server using SQL Server Management studio with the credentials you provided. This means the same credentials you use in php not the windows authentication credentials. You should be able to have both connections at the same time so you can make changes and test the connection at the same time.
Once you confirm you can connect with management studio here are the php configuration checks:
phpinfo()
in it. Then search for pdo_sqlsrv. If it is present the rest of these checks are probably not necessary but since you've been working this so long probably check them anyway.extension=php_sqlsrv_55_ts.dll
andextension=php_pdo_sqlsrv_55_ts.dll
in that order. but I don't think order matters. and again yours will be 56 and the "ts" may be "nts".Once you are connected to sql server through the auth creditionals in management studio and see pdo_sqlsrv in your phpinfo() here are the last things to look into in your code.
Your code above is still for mssql extension. You probably just didn't update it with your latest changes. For sql server extension your code should look like this:
$connectionInfo = array( 'UID' => $dbuser, 'PWD' => $dbpass, 'LoginTimeout' => 1, ); $host = $host . ', ' . $port; $connection = sqlsrv_connect($host, $connectionInfo); $error_messages = sqlsrv_errors();
For windows authentication exclude the uid and pwd.
$connectionInfo = array(); $conn = sqlsrv_connect( $host, $connectionInfo);
If you have more issues please tell me which step is not working so we can dig into more detail with that step.