2

I'm getting the error above when issuing

 isql 'odbc:Driver={ODBC Driver 11 for SQL Server};SERVER=<redacted>;DATABASE=<redacted>;' username password -v

as root on my Linux CentOS 6.7.

The following bcp command works, so the driver should be working correctly:

bcp master.INFORMATION_SCHEMA.TABLES out OutFile.dat -S <redacted> -U user -P password

Also this command works:

sqlcmd -Sg<redacted> -Uuser -Ppassword

Also this PHP script, if run from command line as root, will return an error:

<?php
$connStr = 'odbc:Driver={ODBC Driver 11 for SQL Server};SERVER=<redacted>;DATABASE=<redacted>;';
$dbUser = '<redacted>';
$dbPass = '<redacted>';

$db = new PDO($connStr, $dbUser, $dbPass);
?>

[root@ru000397 ~]# php prova.php
PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /root/prova.php:6
Stack trace:
#0 /root/prova.php(6): PDO->__construct('odbc:Driver={OD...', '<redacted>', '<redacted>')
#1 /root/prova.php(10): db_connect()
#2 {main}
  thrown in /root/prova.php on line 6

I already installed Microsoft ODBC Driver 11 for SQL Server for Linux (https://msdn.microsoft.com/library/hh568451(SQL.110).aspx) and unixODBC 2.3.0 without issues.

My main goal is to be able to connect to MS SQL instance via PHP PDO using ODBC.

TheBeege
  • 47
  • 1
  • 8
Marco Marsala
  • 471
  • 3
  • 7
  • 14

1 Answers1

2

The PDO connection couldn't find the driver for me when using the curly braces. After removing those, I was able to connect just fine.

Note my usage of the double quotes for the connection string which allows variable expansion.

$mssqldriver = 'ODBC Driver 11 for SQL Server';
$connStr = "odbc:Driver=$mssqldriver;SERVER=<redacted>;DATABASE=<redacted>;";
Jeff Puckett
  • 229
  • 5
  • 15