MSSQL Server的适用于Linux和PHP 5.4的本机ODBC驱动程序 [英] MSSQL Server's Native ODBC Driver for Linux and PHP 5.4
问题描述
我在Linux Debian 6 x64上具有Apache 2.2.16和PHP 5.4.3.
I have Apache 2.2.16 and PHP 5.4.3 on a Linux Debian 6 x64.
要为Linux安装MSSQL Server的本机ODBC驱动程序,请按照以下说明进行操作: http://www .codesynthesis.com/〜boris/blog/2011/12/02/microsoft-sql-server-odbc-driver-linux/
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文件:
I configured my odbc.ini file this way:
[mydsn]
Driver = SQL Server Native Client 11.0
Database = datbase
Server = xxx.xxx.xxx.xxx,port
和我的odbcinst.ini这样:
and my odbcinst.ini this way:
[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
要测试,我运行以下命令:
To test, I run the following command:
$ isql -v mydsn dbusername dbpassword
我成功了:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
然后,使用phpize在PHP 5.4上使用以下命令安装unixODBC: (使用第一个命令ln -s ...是因为./configure在默认位置找不到php的标头)
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()上,我得到:
On my phpinfo() I get:
PDO support - enabled
PDO drivers - odbc
PDO Driver for ODBC (unixODBC) - enabled
ODBC Connection Pooling - Enabled, strict matching
现在是时候在PHP 5.4脚本上测试所有内容了:
Now it's time to test everything on a PHP 5.4 script:
<?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>";
}
?>
但是它不起作用...我收到此错误消息:
But it doesn't work... I got this error message:
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
所以我的问题是:会发生什么?我缺少什么配置? 如何在Linux和PHP 5.4上正确设置MSSQL Server的本机ODBC驱动程序?
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?
附注:当我尝试使用odbc_connect()时,PHP说该功能不存在.
Ps.: When I try to use the odbc_connect() PHP says the function doesn't exist.
推荐答案
适用于Linux的MSSQL Server的本机ODBC驱动程序具有错误在其上
MSSQL Server's Native ODBC Driver for Linux has a bug on it
要正确连接MS SQL Server,请使用FreeTDS 有关更多详细信息,请参见: PHP在Linux上的5.4:如何与MS SQL Server 2008连接?
To connect MS SQL Server correctly, use FreeTDS See more details in : PHP 5.4 on Linux: How to connect with MS SQL Server 2008?
这篇关于MSSQL Server的适用于Linux和PHP 5.4的本机ODBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!