tags:

views:

1203

answers:

2
  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?

A: 

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?

Toby Allen
+1  A: 

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

Tom Haigh