致命错误:类“COM” 尝试使用 ADODB 时未找到

发布于 2024-07-08 20:23:23 字数 668 浏览 7 评论 0原文

        include('adodb5/adodb.inc.php');

        $myServer = "localhost";
        $myUser = "root";
        $myPass = "root";
        $myDB = "database";

        //create an instance of the  ADO connection object
        $conn = new COM("ADODB.Connection") or die("Cannot start ADO");

        //define connection string, specify database driver
        $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
        $conn->open($connStr); //Open the connection to the database 

这是我第一次遇到 ADODB 库,据说它会帮助我从 MySQL 切换到 Microsoft SQL Server。 有谁知道为什么我会收到此错误,或者是否有一种更简单的方法,不涉及使用 php.ini 文件?

        include('adodb5/adodb.inc.php');

        $myServer = "localhost";
        $myUser = "root";
        $myPass = "root";
        $myDB = "database";

        //create an instance of the  ADO connection object
        $conn = new COM("ADODB.Connection") or die("Cannot start ADO");

        //define connection string, specify database driver
        $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
        $conn->open($connStr); //Open the connection to the database 

This is the first time I have come across the ADODB library and it supposedly is going to help me switch over from MySQL to Microsoft SQL Server. Does anyone know why i am getting this error or if there is a simpler way that does not involve playing around with the php.ini file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无敌元气妹 2024-07-15 20:23:23

如果您想使用以下代码:

new COM("ADODB.Connection") 

您需要在 PHP 中启用“COM 支持”,例如使用 com_dotnet 扩展 (php_com_dotnet.dll) 如何安装COM扩展

If you want to use following code:

new COM("ADODB.Connection") 

you need to enable "COM support" in PHP, such using the com_dotnet extension (php_com_dotnet.dll) How to install COM extension

枕头说它不想醒 2024-07-15 20:23:23

看来您包含了 PHP adodb 库,但实际上并没有使用它 - 而是尝试实例化(微软)ADO COM 对象。

如果您没有安装 ADO/从 PHP 工作,您可以尝试使用 ODBC DSN-less 连接,例如:

include('adodb5/adodb.inc.php');

$myServer = "localhost";
$myUser = "root";
$myPass = "root";
$myDB = "database";


$db = ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server={{$myServer}};Database={{$myDB}};";
$db->Connect($dsn,$myUser,$myPass) or die($db->ErrorMsg());         

if (!$rs = $db->Execute('select * from table')) die($db->ErrorMsg());

while (!$rs->EOF) {
    print_r($rs->fields);
    $rs->MoveNext();
}

$rs->Close();   

另请参阅 http://phplens.com/adodb/code.initialization.html#connect_ex

It seems that you are including the PHP adodb library, but then not actually using it - instead trying to instanciate a (microsoft) ADO COM object.

If you don't have ADO installed / working from PHP you could try using an ODBC DSN-less connection like:

include('adodb5/adodb.inc.php');

$myServer = "localhost";
$myUser = "root";
$myPass = "root";
$myDB = "database";


$db = ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server={{$myServer}};Database={{$myDB}};";
$db->Connect($dsn,$myUser,$myPass) or die($db->ErrorMsg());         

if (!$rs = $db->Execute('select * from table')) die($db->ErrorMsg());

while (!$rs->EOF) {
    print_r($rs->fields);
    $rs->MoveNext();
}

$rs->Close();   

Also see other connection examples at http://phplens.com/adodb/code.initialization.html#connect_ex

宁愿没拥抱 2024-07-15 20:23:23

最可能的原因是服务器上未正确安装 ADO。 尝试运行最新版本的 MDAC 并确保其安装正确,然后重新尝试。 使用更多信息更新您的问题以获取更多详细信息。 我假设您使用的是 Windows Server?

The most likely cause is that ADO is not correctly installed on the server. Try running the latest version of MDAC and insure it install correctly then try agin. Update your question with more information for further details. I assume you are on a Windows Server?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文