php odbc驱动,PHP: ODBC and DB2 (PDO) - Manual

MSSQL - PHP on Apache - Linux Redhat

When using php 5.2.10 please beaware of this error:

http://bugs.php.net/bug.php?id=42068

Standard odbc_connect will not work, you must use pdo_odbc

Connecting to MSSQL using pdo odbc - walkthrough..

1. Download and configure FreeTDS with-unixodbc

./configure --prefix=/opt/SYSfreetds --with-unixodbc

make;make test; make install

2. install php-odbc and unixODBC

php-odbc-5.2.10-1.x86_64.rpm

unixODBC.x86_64.x86x64

3. Setup ODBC links

a)

Create a tds.driver file with the following contents

[FreeTDS]

Description     = v0.63 with protocol v8.0

Driver          = /opt/SYSfreetds/lib/libtdsodbc.so

Register the ODBC driver - the tds.driver file

odbcinst -i -d -f tds.driver

b)

Creating a tds.datasource file - ODBC Data Source with contents:

[SOURCENAME]

Driver=FreeTDS

Description=Test MS SQL Database with FreeTDS

Trace=No

Server=BobTheServer

Port=1433

TDS Version=8.0

Database=youDBname

Register the ODBC data source

odbcinst -i -s -f tds.datasource

Beware that the odbc.ini file will be installed in the current users home directory. This may need to be used if you are using a webserver as the apache home directory could be different.

Ensure .odbc.ini is in apaches home directory, possibly "/var/www"

4. Test the ODBC link on the command line

isql -v SOURCENAME 'username' 'password'

+---------------------------------------+

| Connected!                            |

|                                       |

| sql-statement                         |

| help [tablename]                      |

| quit                                  |

|                                       |

+---------------------------------------+

SQL>

5. Edit /etc/php.ini

Make sure the following is set:

mssql.secure_connection = On

6. Restart apache gracefully

7. PHP to run:

$dbh= new PDO('odbc:SOURCENAME', 'username', 'password');

$stmt = $dbh->prepare("$query");

$stmt->execute();

while ($row = $stmt->fetch()) {

print_r($row);

}

unset($dbh); unset($stmt);

?>

Trouble-shooting:

Please try strace/ truss if you encounter issues. It could be you are referencing wrong libraries somewhere.

Ensure you have restarted apache once the odbc files are in place

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值