2

I've been tasked with taking all of our MySQL databases and migrating them to SQL Server. In attempting to get PHP 5.3.24 to work with MSSQL, I've done the following:

Copied the non thread-safe drivers to /php/ext.

Updated my php.ini file to include the following two lines:

extension=php_pdo_sqlsrv_53_nts_vc9.dll;
extension=php_sqlsrv_53_nts_vc9.dll

Restarted IIS 7 running on Windows Server 2008 R2.

phpinfo shows sqlsrv under Registered PHP Streams, and sqlsrv also appears under PDO drivers and pdo_sqlsrv support shows as "enabled." Yet, when I try to connect via my application, I get the following:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\mystuff\myphpconnectfile.php

My connect string looks like this:

$con = new PDO("mssql:host=xxx.xxx.xxx.xxx,1433;dbname=mydb", "user", "pwd");
$con -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return($con);

Looks like it's finding the server okay, but not the PHP/PDO mssql drivers. What have I missed?

EDIT: Configure Command under phpinfo shows the lines "--without-mssql" "--without-pdo-mssql". I don't know where to go to change this, or if it's necessary.

6
  • Why on earth does one want to migrate from MySQL to MS-SQL?!? Commented Nov 18, 2013 at 12:20
  • 1
    Try new PDO('sqlsrv: ... '); instead of new PDO('mssql: ... '); Commented Nov 18, 2013 at 12:21
  • @arkascha: Believe me, it was not my idea, and I fought it. We're getting along fantastically with MySQL, but TPTB have decided that, for interoperability, everything needs to be in SQL Server. Lucky me. Commented Nov 18, 2013 at 12:22
  • @FDL: That got me somewhere. I'm now getting this error: An invalid keyword 'host' was specified in the DSN string. Do I need to rewrite my connection string? Commented Nov 18, 2013 at 12:24
  • 1
    @Chris yeh, sqlsrv:Server=xxx,1433;Database=mydb Commented Nov 18, 2013 at 12:26

1 Answer 1

3

You're using an invalid DSN connection string for MSSQL. You need to use the format found here.

new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx,1433;Database=mydb', 'user', 'pwd');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.