使用PEAR MDB2从IIS上的PHP连接到MS SQL [英] Connecting to MS SQL from PHP on IIS using PEAR MDB2

查看:143
本文介绍了使用PEAR MDB2从IIS上的PHP连接到MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉在这里问这个问题; php.net似乎充满了关于此的例外和借口。

Sorry to have to ask this here; php.net just seems to be full of exceptions and excuses regarding this.

我正在使用PHP 5.3.6运行IIS 6.0。我已经安装了MDB2并且正在工作(即使是为非品牌RDBMS定制的驱动程序)。这一切都很有效。但现在我需要让PHP连接到一些标准技术:MS SQL。

I'm running IIS 6.0 with PHP 5.3.6. I've got MDB2 installed and working (even with a custom-written driver for an off-brand RDBMS). That's all working great. But now I need to have PHP connect to a bit of standard technology: MS SQL.

问题是MDB2的mssql驱动程序要求PHP已经用特殊标志。很难处理php二进制文件:)。

The problem is the mssql driver for MDB2 requires PHP to have been compiled with special flags. Hard to do with php binaries :).

我可以继续获取编译器,下载源代码并重新编译,但我只是开始怀疑是否当我实际上有一种更好,更标准的方式来完成工作时,我已经在杂草中了。

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.

所以,我的问题是:对于IIS 6 + PHP 5.3。 6,是否有一个不同的,更容易的,更常见的连接到MS SQL的路线?

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?

推荐答案

正如你所说的那样指出,对社区 mssql 驱动程序的支持未编译到最新的Windows PHP二进制文件中。

As you've rightly pointed out, support for the community mssql driver is not compiled into the latest Windows PHP binaries.

目前当前的稳定版本的MDB2(2.4.1)不支持官方微软 sqlsrv 本机驱动程序。

Presently the current stable release of MDB2 (2.4.1) does not support the official Microsoft sqlsrv native driver.

但是如果你我愿意在MDB2的beta版本中生活在边缘,然后一切都不会丢失。有一个Microsoft本机 sqlsrv 驱动程序是2.5.0b3版本的一部分:

However if you're willing to live on the edge a bit with the beta release of MDB2 then all is not lost. There is a Microsoft native sqlsrv driver that is part of the 2.5.0b3 release:


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

首先确保你已按照我在此处的回答中所述安装了Microsoft本机驱动程序:

First of all ensure that you've installed the Microsoft native driver as I described in my answer here:


IIS上的MSSQL和PHP 5.3.5之间的连接无法正常工作

然后要安装PEAR MDB2 sqlsrv驱动程序,请执行以下操作:

Then to install the PEAR MDB2 sqlsrv driver do the following:


  1. 如果您已经安装了MDB2,请将其卸载:

  1. If you've already installed MDB2 then uninstall it:

pear uninstall mdb2

如果您已经安装了任何驱动程序然后你需要先卸载这些:

If you already have any drivers installed then you'll need to uninstall these first:

pear uninstall mdb2 #mysql

接下来告诉PEAR你想要允许非稳定的beta包:

Next tell PEAR that you want to allow non-stable beta packages:

pear config-set preferred_state beta

安装 MDB2_Driver_sqlsrv

pear install MDB2_Driver_sqlsrv

这将安装最新的MDB2 beta和MS sqlsrv驱动程序:

This will install the latest MDB2 beta and the MS sqlsrv driver:


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 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"


  • 可能建议将PEAR重新打包,只允许再次使用稳定的包装

  • It's probably advisable to knock PEAR back to only allowing stable packages again

    pear config-set preferred_state stable

    我刚用以下测试脚本尝试了这个,我能够连接到我的本地MS SQL Server并检索一些数据:

    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:

    <?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/>";
    }
    
    ?>
    

    这篇关于使用PEAR MDB2从IIS上的PHP连接到MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆