我有Apache 2.2.16和PHP 5.4.3在Linux Debian 6x64上。
To install the MSSQL Server s Native ODBC Driver for Linux, I use the following instructions: http://www.codesynthesis.com/~boris/blog/2011/12/02/microsoft-sql-server-odbc-driver-linux/
我以这种方式配置了我的Odbc.ini文件 :
[mydsn]
Driver = SQL Server Native Client 11.0
Database = datbase
Server = xxx.xxx.xxx.xxx,port
和我的辣椒 尼尼这样:
[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading=1
UsageCount=1
为了测试,我执行以下命令:
$ isql -v mydsn dbusername dbpassword
我获得了成功:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
Then, a use phpize to install unixODBC on PHP 5.4, using this: (The first command, ln -s ..., is used because ./configure can t find the headers of php on the default location)
$ sudo ln -s /usr/include/php5 /usr/include/php
$ phpize
$ ./configure --with-pdo-odbc=unixODBC && make && make test
$ sudo make install
在我的phpinfo () 我得到:
PDO support - enabled
PDO drivers - odbc
PDO Driver for ODBC (unixODBC) - enabled
ODBC Connection Pooling - Enabled, strict matching
现在是用PHP 5.4脚本测试一切的时候了:
<?php
ini_set( display_errors , 1);
error_reporting(E_ALL);
$conn = new PDO( odbc:DSN=mydsn;UID= .$usr. ;PWD= .$psw);
$query = select * from my_table ;
$stmt = $conn->prepare($query);
$stmt->execute();
while ($row = $stmt->fetch()) {
echo "<pre>";
print_r($row);
echo "</pre>";
}
?>
但它不起作用... 我收到一个错误信息:
Fatal error: Uncaught exception PDOException with message SQLSTATE[01000] SQLDriverConnect: 0
[unixODBC][Driver Manager]Can t open lib /opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0 : file not found
in /var/www/testemssql.php:17
Stack trace:
#0 /var/www/testemssql.php(17): PDO->__construct( odbc:DSN=mydsn... )
#1 {main} thrown in /var/www/testemssql.php on line 17
So my question is: what is happen? What configuration I m missing? How to set up correctly the MSSQL Server s Native ODBC Driver on Linux and PHP 5.4?
Ps. : 当我尝试使用 odbc_ connect () 时, PHP 表示函数不存在 。