0

如前一个问题中所述freetds并且unixodbc安装在 Lion 上并经过测试isql,我尝试使用 PHP 连接到 MSSQL:

$connection = odbc_connect('SMS_GTWY', 'username', 'password');

但是,它返回:

PHP Warning:  odbc_connect(): SQL error: [iODBC][Driver Manager]Specified driver could not be loaded, SQL state IM003 in SQLConnect in testodbc.php line 3

[iODBC][Driver Manager]Specified driver could not be loaded

我该如何解决?

$ cat /tmp/odbc_trace上述PHP执行后的PS输出:

** iODBC Trace file
** Trace started on Fri Dec 14 18:03:27 2012
** Driver Manager: 03.52.0607.1008


[000000.000472]
php             7FFF738F8960 EXIT  SQLConnect with return code -1 (SQL_ERROR)
        SQLHDBC           0x7fbec48a77d0
        SQLCHAR         * 0x10e2e8ea8
        SQLSMALLINT       -3 (SQL_NTS)
        SQLCHAR         * 0x10e2e7300
        SQLSMALLINT       -3 (SQL_NTS)
        SQLCHAR         * 0x10e1873fa
        SQLSMALLINT       -3 (SQL_NTS)

[000000.000540]
php             7FFF738F8960 ENTER SQLError
        SQLHENV           0x7fbec48a7560
        SQLHDBC           0x7fbec48a77d0
        SQLHSTMT          0x0 (SQL_NULL_HANDLE)
        SQLCHAR         * 0x7fff6d1adf42
        SQLINTEGER      * 0x7fff6d1adf3c
        SQLCHAR         * 0x7fff6d1adf48
        SQLINTEGER        511
        SQLSMALLINT     * 0x7fff6d1adf3a

[000000.000598]
php             7FFF738F8960 EXIT  SQLError with return code 0 (SQL_SUCCESS)
        SQLHENV           0x7fbec48a7560
        SQLHDBC           0x7fbec48a77d0
        SQLHSTMT          0x0 (SQL_NULL_HANDLE)
        SQLCHAR         * 0x7fff6d1adf42
                  | IM003                                    |
        SQLINTEGER      * 0x7fff6d1adf3c (0)
        SQLCHAR         * 0x7fff6d1adf48
                  | [iODBC][Driver Manager]Specified driver  |
                  | could not be loaded                      |
        SQLINTEGER        511
        SQLSMALLINT     * 0x7fff6d1adf3a (59)

[000000.000784]
php             7FFF738F8960 ENTER SQLFreeConnect
        SQLHDBC           0x7fbec48a77d0

[000000.000807]
php             7FFF738F8960 EXIT  SQLFreeConnect with return code 0 (SQL_SUCCESS)
        SQLHDBC           0x7fbec48a77d0
4

1 回答 1

1

要修复,请使用FREETDSCONFODBCINI和设置环境ODBCINSTINI

<?php

  putenv("FREETDSCONF=/Users/ohho/.freetds.conf");
  putenv("ODBCINI=/Users/ohho/.odbc.ini");
  putenv("ODBCINSTINI=/Users/ohho/.odbcinst.ini");

  $connection = odbc_connect('SMS_GTWY', 'sms_gtwy', 'sms_gtwy');

?>
于 2012-12-14T11:03:21.490 回答