English 中文(简体)
MSSQL服务器 Linux 和 PHP 5.4 的本地 ODBC驱动器
原标题:MSSQL Server s Native ODBC Driver for Linux and PHP 5.4

我有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 表示函数不存在 。

最佳回答

MSSQL 服务器的本地 ODBC 驱动程序 Linux 的驱动程序有 < a href=" https://bugs.php.net/bug.php?id= 61777" rel= "nofollow noreferrer" >bug

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?

问题回答

我知道现在有点晚了, 但是因为我撞上这条线, 却撞到头顶,

(1) 1) 检查 libsqlncli -11.0.so179.0.0 上的权限,以确保 Apache 正在运行的任何用户都能够访问它( 应该有读和执行)

2) 使用 eldd 检查是否缺少任何依附关系 - 基于Isql 正在工作,

ldd/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so179.0.0

3) 从命令行而不是通过 Apache 运行您的php 脚本。 如果它这样工作, 请去停止 4 。 如果它不这样做, 我建议通过 sterrace 运行, 看看它实际上在做什么 。

4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 4) 3) 3) 3) 3)\ \fs 3)\fs 3\ \ \ 3\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

取消 SELinux 的精密命令可能根据您的操作系统而有所不同, 但对我来说( 在 CentOS 上), 这个有效 :

http://rbgeek.wordpress.com/2012/08/06/how-to-disable-selinux-on-centos-ununtre-referr/>http://rbgeek.wordpress.com/2012/08/06/how-to-disable-selinux-on-centos-ununtrest-repotting/ http://rbgeek.wordpress.com/2012/08/06/how-to-to-diable-selinux-on-centos-unrestopting/

祝你好运!

同一配置, odbcinst. ini 除外 :

[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
UsageCount=1

删除此行后重试 :

Threading=1

你的php剧本对我很好

希望这能帮到你

如果您用连接的补丁补丁和复数php“https://bugs.php.net/bug.php?id=61777” rel=“nofollow”>https://bugs.php.net/bug.php?id=61777 的补丁来解决这个问题。

也检视此博客文章中的 DSN 与使用的例子:

< a href=>http://strangenut.com/blogs/dacrowlah/archive/2012/04/13/安装和使用微软-sql-sql-server-odbc-driver-for-linux.aspx" rel=“nofollow'>http://strangenut.com/blogs/dacrowlah/archive/2012/04/13/reading-and-useing-the-microsoft-sql-serverer-odbc-driver-for-linux.aspx

我从来没有机会自己尝试, 但我听说php5 -sybase 工作很好, 我知道它可以使用 Debian 和 Ubuntu 在仓库里。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签