Connecting to MSSQL server in PHP using integrated authentication -
i have xampp running on ms server 2012 r2. need make connection mssql server accepts integrated win authentication.
if try below, login failure , error log on sql server sql authentication not option. accepts connection user. php script not being run under 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
not option. tried load php drivers it's not working. can't change authentication sql server , can't use other version of php.
i can't turn secure_connection on have able connect other sql servers requires "normal" sql authentication:
mssql.secure_connection = off
how connect problematic sql server?
update: upgraded xampp
latest version. php
version 5.6.8
still can't use sqlsrv_connect()
though installed necessary driver , added every single dll php.ini
. restarted apache
several times. clue?
error msg: fatal error: call undefined function sqlsrv_connect()
ok. it's hard debug server issue without being on server i've done lot php , sql server best share experiences.
first, glad updated 5.3.1 version of php ancient , insecure. here sanity checks system. may nothing of worth checking.
first make sure can connect sql server using sql server management studio credentials provided. means same credentials use in php not windows authentication credentials. should able have both connections @ same time can make changes , test connection @ same time.
- enable tcp. sql server configuration manager -> sql server network configuration -> protocols sqlexpress -> tcp/ip (right click)-> properties -> enabled (yes) -> ip addresses -> ipall -> tcp port 1433 -> ok
- enable sql server auth. select server (right click) -> properties -> security -> sql server , windows authentication mode -> ok
- open sql server port on firewall. windows control panel -> system , security -> windows firewall -> advanced settings -> inbound rules -> new rule -> port -> tcp -> 1433 (or whatever) -> allow connection -> next -> name -> sql server -> finish -> restart computer.
- of course if want connect through non-default user need add user: sql server -> security -> logins (right click) -> add login -> server roles -> sysadmin -> ok
- if make of these changes restart sql server: sql server configuration manager -> sql server services -> sql server (right click) -> restart.
once confirm can connect management studio here php configuration checks:
- you can see if extension available creating php page function
phpinfo()
in it. search pdo_sqlsrv. if present rest of these checks not necessary since you've been working long check them anyway. - sql_srv extension php should version 3.2 php 5.6 can obtain library here
- version 3.2 requires os extension available here check other requirements on previous link. os may use different extension 1 linked here.
- find php extensions directory. {php-install-directory}/ext. make sure copy appropriate version of downloaded sqlsrv libraries directory. mine called "php_sqlsrv_55_ts.dll" , "php_dpo_sqlsrv_55_ts.dll" yours have 56 instead of 55 think , "ts" should match php install. "ts" means thread safe, other option "nts" not thread safe. 1 use dependent on php install.
- my php.ini file contains these lines
extension=php_sqlsrv_55_ts.dll
,extension=php_pdo_sqlsrv_55_ts.dll
in order. don't think order matters. , again yours 56 , "ts" may "nts". - if made changes based on these make sure restart apache check if pdo_sqlsrv in phpinfo() report. after restarting apache check apache , php error log see if specific errors php trying load extensions. post here if need them.
- you can see if extension available creating php page function
once connected sql server through auth creditionals in management studio , see pdo_sqlsrv in phpinfo() here last things in code.
your code above still mssql extension. didn't update latest changes. sql server extension code should 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 uid , pwd.
$connectioninfo = array(); $conn = sqlsrv_connect( $host, $connectioninfo);
if have more issues please tell me step not working can dig more detail step.
Comments
Post a Comment