简体   繁体   English

使用 PEAR MDB2 从 IIS 上的 PHP 连接到 MS SQL

[英]Connecting to MS SQL from PHP on IIS using PEAR MDB2

Sorry to have to ask this here;很抱歉不得不在这里问这个; php.net just seems to be full of exceptions and excuses regarding this. php.net 似乎对此充满了例外和借口。

I'm running IIS 6.0 with PHP 5.3.6.我正在运行 IIS 6.0 和 PHP 5.3.6。 I've got MDB2 installed and working (even with a custom-written driver for an off-brand RDBMS).我已经安装并运行了 MDB2(即使是为非品牌 RDBMS 定制的驱动程序)。 That's all working great.这一切都很好。 But now I need to have PHP connect to a bit of standard technology: MS SQL.但现在我需要让 PHP 连接到一些标准技术:MS SQL。

The problem is the mssql driver for MDB2 requires PHP to have been compiled with special flags .问题是 MDB2 的 mssql 驱动程序要求 PHP 已使用特殊标志进行编译。 Hard to do with php binaries:).很难处理 php 二进制文件:)。

I could go down the road of getting a compiler, downloading the source and recompiling, but I'm just starting to wonder if I'm out in the weeds when there's actually a better, more standard way of getting the job done.我可以 go 沿着获得编译器、下载源代码和重新编译的道路前进,但我刚刚开始怀疑当实际上有更好、更标准的方式来完成工作时,我是否已经陷入困境。

So, my question is: For IIS 6 + PHP 5.3.6, is there a different, easier, more commonly-tread route to connecting to MS SQL?所以,我的问题是:对于 IIS 6 + PHP 5.3.6,是否有不同的、更简单、更常用的路径连接到 MS Z9778840A0100CB30C982876741B0B52A?

As you've rightly pointed out, support for the community mssql driver is not compiled into the latest Windows PHP binaries.正如您正确指出的那样,对社区mssql驱动程序的支持未编译到最新的 Windows PHP 二进制文件中。

Presently the current stable release of MDB2 (2.4.1) does not support the official Microsoft sqlsrv native driver.目前 MDB2 (2.4.1) 的当前稳定版本不支持微软官方的sqlsrv原生驱动。

However if you're willing to live on the edge a bit with the beta release of MDB2 then all is not lost.但是,如果您愿意在 MDB2 的 beta 版本中稍稍靠边一点,那么一切都不会丢失。 There is a Microsoft native sqlsrv driver that is part of the 2.5.0b3 release:有一个 Microsoft 本机sqlsrv驱动程序,它是 2.5.0b3 版本的一部分:

http://pear.php.net/package/MDB2_Driver_sqlsrv http://pear.php.net/package/MDB2_Driver_sqlsrv

First of all ensure that you've installed the Microsoft native driver as I described in my answer here:首先确保您已按照我在此处的回答中的描述安装了 Microsoft 本机驱动程序:

Connection between MSSQL and PHP 5.3.5 on IIS is not working MSSQL 和 IIS 上的 PHP 5.3.5 之间的连接不起作用

Then to install the PEAR MDB2 sqlsrv driver do the following:然后要安装 PEAR MDB2 sqlsrv 驱动程序,请执行以下操作:

  1. If you've already installed MDB2 then uninstall it:如果您已经安装了 MDB2,请卸载它:

    pear uninstall mdb2

    If you already have any drivers installed then you'll need to uninstall these first:如果您已经安装了任何驱动程序,那么您需要先卸载这些驱动程序:

    pear uninstall mdb2#mysql

  2. Next tell PEAR that you want to allow non-stable beta packages:接下来告诉 PEAR 你想允许不稳定的 beta 包:

    pear config-set preferred_state beta

  3. Install MDB2_Driver_sqlsrv安装MDB2_Driver_sqlsrv

    pear install MDB2_Driver_sqlsrv

    This will install the latest MDB2 beta and the MS sqlsrv driver:这将安装最新的 MDB2 beta 和 MS sqlsrv 驱动程序:

     downloading MDB2_Driver_sqlsrv-1.5.0b3.tgz... Starting to download MDB2_Driver_sqlsrv-1.5.0b3.tgz (29,468 bytes).........done: 29,468 bytes downloading MDB2-2.5.0b3.tgz... Starting to download MDB2-2.5.0b3.tgz (130,865 bytes)...done: 130,865 bytes install ok: channel://pear.php.net/MDB2_Driver_sqlsrv-1.5.0b3 install ok: channel://pear.php.net/MDB2-2.5.0b3 MDB2: Optional feature fbsql available (Frontbase SQL driver for MDB2) MDB2: Optional feature ibase available (Interbase/Firebird driver for MDB2) MDB2: Optional feature mssql available (MS SQL Server driver for MDB2) MDB2: Optional feature mysql available (MySQL driver for MDB2) MDB2: Optional feature mysqli available (MySQLi driver for MDB2) MDB2: Optional feature oci8 available (Oracle driver for MDB2) MDB2: Optional feature odbc available (ODBC driver for MDB2) MDB2: Optional feature 正在下载 MDB2_Driver_sqlsrv-1.5.0b3.tgz...开始下载 MDB2_Driver_sqlsrv-1.5.0b3.tgz(29,468 字节).........完成:29,468 字节下载 MDB2-2.5.0b3.tgz...开始下载 MDB2-2.5.0b3.tgz(130,865 字节)...完成:130,865 字节安装成功:channel://pear.php.net/MDB2_Driver_sqlsrv-1.5.0b3 安装确定:channel://pear.php.net /MDB2-2.5.0b3 MDB2:可选功能 fbsql 可用(Frontbase SQL 驱动程序适用于 MDB2) MDB2:可选功能 ibase 可用(Interbase/Firebird 驱动程序适用于 MDB2) MDB2:可选功能 mssql 可用(MS Z9778840A0100CB30C2582876741B0 可选服务器驱动程序适用于 MDBZ) feature mysql available (MySQL driver for MDB2) MDB2: Optional feature mysqli available (MySQLi driver for MDB2) MDB2: Optional feature oci8 available (Oracle driver for MDB2) MDB2: Optional feature odbc available (ODBC driver for MDB2) MDB2: Optional feature pgsql available (PostgreSQL driver for MDB2) MDB2: Optional feature querysim available (Querysim driver for MDB2) MDB2: Optional feature sqlite available (SQLite2 driver for MDB2) MDB2: Optional feature sqlsrv available (MS SQL Server driver for MDB2) MDB2: To install optional features use "pear install pear/MDB2#featurename" pgsql 可用(MDB2 的 PostgreSQL 驱动程序) MDB2:可选功能 querysim 可用(MDB2 的 Querysim 驱动程序) MDB2:可选功能 sqlite 可用(MDB2 的 SQLite2 驱动程序) MDB2:可选功能 sqlsrv 可用(MS Z9778840A0100CB30C982876741B0B5A2 安装服务器驱动程序) MDB2:可选功能使用“pear install pear/MDB2#featurename”
  4. It's probably advisable to knock PEAR back to only allowing stable packages again建议将 PEAR 重新设置为只允许稳定包

    pear config-set preferred_state stable

I just tried this with the following test script and I was able to connect to my local MS SQL Server and retrieve some data:我刚刚使用以下测试脚本进行了尝试,我能够连接到我的本地 MS SQL 服务器并检索一些数据:

<?php
require_once 'MDB2.php';

$dsn = array(
    'phptype'  => 'sqlsrv',
    'username' => 'test',
    'password' => 'testpass',
    'hostspec' => 'localhost',
    'database' => 'PEARMDBTEST',
);

$mdb2 =& MDB2::connect($dsn);

if(PEAR::isError($mdb2)) 
{
    die($mdb2->getMessage());
}

$res =& $mdb2->query('SELECT * FROM TestData');

while (($row = $res->fetchRow())) {
    echo $row['TestDataRow'] . "<br/>";
}

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM