3

I'm trying to connect to a MSSQL database using PDO with odbc. I'm aware that there's a package SqlSrv (but for some reason that package (.dll) won't load properly). So I found some documentation arguing it's also possible with PDO. In my PHP.ini I've enabled the extension php_pdo_odbc.dll and it loads fine.

My connection string looks like this:

$conn = new PDO(
    'odbc:
        Driver=SQL Server;
        Server=MyServer\MyInstance;
        Database=MyDatabaseName;
        Trusted Connection=Yes;',
    'MyWindowsUserName',
    'MyWindowsPassword'
);

I've tried various properties (for example by prepending the domain to the username, switching with the authentication options User Id, UID, Password, PWD and Trusted Connection) but I keep getting the message

SQLSTATE[28000] SQLDriverConnect: 18456 [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'MyWindowsUserName'.

Any suggestions on how to connect to the database with my Windows Account? (that's the only way for me to connect to the database)

Ferrmolina
  • 2,737
  • 2
  • 30
  • 46
Ben Fransen
  • 10,884
  • 18
  • 76
  • 129
  • I'd try to figure out why SqlSrv isn't working. It's the "official" way so it would be easier to manage long term. – Anton Apr 13 '15 at 13:53

2 Answers2

1

Try removing the username & password

$conn = new PDO(
    'odbc:
        Driver=SQL Server;
        Server=MyServer\MyInstance;
        Database=MyDatabaseName;
        Trusted Connection=Yes;'
);
Jon Tirjan
  • 3,556
  • 2
  • 16
  • 24
  • Unfortunately this doesn't work (I've already tried it). When I don't provide any credentials it tries to connect as the server's name. – Ben Fransen Apr 14 '15 at 09:47
-1

I have authenticated by Windows with following PHP statement: This is my code:

$ Conn = new PDO ("odbc: Driver = {SQL Server}; Server=JAMILI-PC\SQLEXPRESS; null; null");
  • I am using Windows 2008.
  • I hope it solves your problem.
Orlando Herrera
  • 3,481
  • 1
  • 34
  • 44
Luis D
  • 1
  • 1