Page 1 of 1

PHP with MSSQL OLEDB, ADO GetRows() problem.

Posted: Fri Feb 24, 2012 12:14 am
by DrDev
Hi,

I'm running PHP on IIS with an MS SQL Server and I'm having a problem with ADOdb: http://phplens.com/adodb/index.html

This is my code:

Code: Select all

<?php
$connTest = new COM("ADODB.Connection") or die("Cannot start ADO");
$connTest->Open("Provider=SQLOLEDB.1;Password=xxxxxxx;Persist Security Info=True;User ID=xxxxxx;Initial Catalog=xxxxxxxx;Data Source=xxxxx"); 
$rsTest = $connTest->Execute("SELECT * FROM tbl_Customers");
$arrTest = $rsTest->GetRows();
if (is_array($arrTest)){
	for ($intCount=0; $intCount < count($arrTest) ; $intCount++){
		$intTestID =  $arrTest[$intCount][0];
		$strText =  $arrTest[$intCount][1];
		$decTest =  $arrTest[$intCount][2];
		$datTest =  $arrTest[$intCount][3];
		
		echo $intTestID." - ".$strText." - ".$decTest." - ".$datTest."<br />";
	}
}
else echo "Array Empty";

$rsTest->Close(); 
$rsTest = null;
$connTest->Close(); 
$connTest = null;
?>
There seems to be a problem with the GetRows(), ADODB and SQLODB combination, because if I simply loop through the recorset like this, it works fine:

Code: Select all

<?php
$connTest = new COM("ADODB.Connection") or die("Cannot start ADO");  
$connTest->Open("Provider=SQLOLEDB.1;Password=xxxxxxx;Persist Security Info=True;User ID=xxxxxx;Initial Catalog=xxxxxxxx;Data Source=xxxxx");
 
$rsTest = $connTest->Execute("SELECT * FROM tbl_Customers"); 
 
while (!$rsTest->EOF) {  
    $fv = $rsTest->Fields("CustomerID"); 
    echo "Value: ".$fv->value."<br>\n"; 
    $rsTest->MoveNext(); 
} 

$rsTest->Close(); 
$rsTest = null;
$connTest->Close(); 
$connTest = null;
?>
Similarly, when I use ADODB with a MySQL, albeit not with an OLEDB connection, I can use GetRows() and it loads a 2 dimensional array just fine and works as expected:

Code: Select all

<?php
$connTest = ADONewConnection("mysql");
$connTest-> Connect($Server, $User, $Pass, $DB);
$rsTest = $connTest->Execute("SELECT * FROM tbl_Test");
$arrTest = $rsTest->GetRows();
if (is_array($arrTest)){
	for ($intCount=0; $intCount < count($arrTest) ; $intCount++){
		$intTestID =  $arrTest[$intCount][0];
		$strText =  $arrTest[$intCount][1];
		$decTest =  $arrTest[$intCount][2];
		$datTest =  $arrTest[$intCount][3];
		
		echo $intTestID." - ".$strText." - ".$decTest." - ".$datTest."<br />";
	}
}
else echo "Array Empty";
?>
Has anyone come across this problem before? And if so what's the solution?